I2C Port Expander MAX7320

markdil

New Member
I am having no luck with controlling a Maxim MAX7320 Expander. I have all eight outputs hooked to LEDs. I am simply just trying to turn them all on.
(That is not the whole purpose, just wanted to try something simple. Obviously, not simple!)

AD0 and AD2 go to ground, making the device address %1011000x. Would someone be so kind as to write a simple code to turn all the LEDs on?

I am using a 08M2 PicAxe chip.

I suspect I am getting crossed up with the acknowledge bit. Just a guess. I am ready to smash the whole setup with a large sledge hammer! Very frustrated. I have used I2C many times before with no problem.

Thanks!
 
Last edited:

westaust55

Moderator
It is always good to try and save me there time in helping you by providing a link to the non PICAXE IC.
In this case here it is:
http://datasheets.maximintegrated.com/en/ds/MAX7320.pdf

Also please post the code you are trying to use.

That you mention getting confused about acknowledge bits, suggests you may not have used i2c on PICAXE chips previously.
With PICAXE chips the inbuilt firmware automatically looks after such things as the read/write bit and the monitoring of the ack response.

As I am accessing the forum via an iPhone at this moment, sorry I am not about to try and write extensive lines of code.
 

Goeytex

Senior Member
This might work ( untested)

Code:
[color=Navy]#picaxe [/color][color=Black]08M2[/color]
[color=Navy]#no_data[/color]


[color=Green]'Tie MAX7320 Pins AD0/AD2 to Ground
'Connect 4k7 Pullup resistors from SDA and SCL to +5v
'Connect Picaxe C.1 (leg/pin 6) to Max7320 SCL
'Connect Picaxe C.2 (leg/pin 5) to Max7320 SDA
'Picaxe BASIC "hsersetup" uses 8-bit address
'Address is therefore %10110000 or $B0[/color]


[color=Blue]hi2csetup i2cmaster[/color][color=Black], [/color][color=Navy]%10110000[/color][color=Black], [/color][color=Blue]i2cslow[/color][color=Black], [/color][color=Blue]i2cbyte

do
    hi2cout ([/color][color=Navy]%11111111[/color][color=Blue])  [/color][color=Green];all on
    [/color][color=Blue]pause [/color][color=Navy]1000
    [/color][color=Blue]hi2cout ([/color][color=Navy]%00000000[/color][color=Blue])  [/color][color=Green];all off 
    [/color][color=Blue]pause [/color][color=Navy]1000  [/color]

[color=Blue]loop
  [/color]
Note: The Max7320 Datasheet example circuit shows the RST Pin connected to the microcontroller and does not say if the pin is internally pulled high. Since RST is "Active Low" it might be a good idea to connect a 10K pullup resistor from MAX 7320 RST to +5V.
 
Last edited:

markdil

New Member
Thanks Goeytex!

That is one of the first things I tried. Also, I have the reset hooked to c.4 so I can control it.

Turns out, in my haste, I forgot the pull-up resistors on the I2C bus. UGH!

It does work now.

expander.jpg
 

markdil

New Member
Here is something interesting. Just been playing with the expander. Presently, this is the code:

pause 10
high c.4 ;reset high
pause 500

hi2csetup i2cmaster, %10110000, i2cslow, i2cbyte

pause 1000

cascade_: ;cascade 8 times

b1=1
for b2=1 to 8
debug
hi2cout (b1)
pause 50
b1=b1+b1
next b2

for b3=1 to 5 ;flash all LEDs five times
debug
hi2cout (%11111111) ;all on
pause 1000
hi2cout (%00000000) ;all off
pause 1000
next b3

goto cascade_

Look at the "b3" loop. For some unknown reason, it only goes through the loop once! It goes through the b2 loop fine. I tried changing the variable, but to no avail. The debug clearly shows once through the loop (b3), then out! It turns all the LEDs on, then off, but just once!

If I change the first [hi2cout (%11111111) ;all on] to [hi2cout (%00111111) ;all on], it goes through the loop perfectly, but of course does not turn all the LEDs on, just six of them. If either of the last two bits are "1", it does not loop.

I need to scrap this project!
 
Last edited:

hippy

Technical Support
Staff member
If it's not going through the 5 loops when you turn all LEDs on but does when you turn only some LEDs on, that suggests turning all LEDs on may be drawing too much power, killing the supply rail, causing the PICAXE to reset, or there may be some short between one of the LEDs not turned on causing a reset issue when it is turned on.

That all LEDs work individually suggests drawing too much power.

Does it work with %11001111, %11110011 and %11111100 ?
 

markdil

New Member
Thanks Hippy, you are correct. The PICAXE was resetting. Guess I need to cascade them so they appear all lit.
 

hippy

Technical Support
Staff member
The real question is why are the LEDs / current drawn causing the PICAXE to reset ?

If you are using batteries then perhaps try with a fresh set.
 

AllyCat

Senior Member
Hi,

I can't see a supply decoupling capacitor on the PCB shown in #4. Also the supply rail track is very narrow and the supply to the LEDs appears to be routed back via the PICaxe supply pin. :(

Leg 3 appears to be marked "reset" which suggests the PCB was designed for an older chip such as an 08 or 08M ? I think it's been suggested that the M2s are much less tolerant of noise on their supply rail (higher speed technology? ).

Cheers, Alan.
 

markdil

New Member
I am using a 3 amp power supply. I am also using a 08M2. The reset is going to the reset pin on the expander chip, not the PicAxe. I just marked it so I knew which pin it was hooked to.

I also added a capacitor, it did not help.
 

hippy

Technical Support
Staff member
It could be that it's not the power supply current causing the problem but perhaps something else. Just a guess but perhaps there's a short with the I2C bus which only materialises when a certain number of LEDs are on, and perhaps when that occurs it could be an I2C issue causes a reset.

I would suggest adding a SERTXD("RESET") at the start of code and SERTXD("OK") after the FOR-NEXT toggling loop which doesn't work with 8 LEDs.

Then check "RESET","OK","OK"... shows for 6 LEDs. Then check that becomes "RESET","RESET"... with 8 LEDs which will prove a PICAXE reset is occurring.

Then, while still controlling 8 LEDs, physically remove two LEDs and check if that now becomes "RESET","OK","OK".
 

westaust55

Moderator
Try bringing the LEDs one one at a time using:

Code:
B4 = 1
FOR B3= 0 to 7
  HI2cOUT (B4)
  PAUSE 1000
  B4 = B4 * 2
NEXT B3
Then watch to LEDs

If it stops after a particular LED then there is a clue.
If LEDs 0 and 1 light up but not 2, then look around the leg of the i2c I/O expander for a short between the pin driving LED2 and that driving LED 3.
 

markdil

New Member
It could be that it's not the power supply current causing the problem but perhaps something else. Just a guess but perhaps there's a short with the I2C bus which only materialises when a certain number of LEDs are on, and perhaps when that occurs it could be an I2C issue causes a reset.

I would suggest adding a SERTXD("RESET") at the start of code and SERTXD("OK") after the FOR-NEXT toggling loop which doesn't work with 8 LEDs.

Then check "RESET","OK","OK"... shows for 6 LEDs. Then check that becomes "RESET","RESET"... with 8 LEDs which will prove a PICAXE reset is occurring.

Then, while still controlling 8 LEDs, physically remove two LEDs and check if that now becomes "RESET","OK","OK".
Those are good thoughts! What I did was put a (pause 10000) for the very first line of the code. When it apparently reset, there was a ten second pause before anything happened again, so I knew it reset. I like your idea better. I will keep that trick in mind!!

I do not believe it should reset but it does. What confuses me is, I can turn on all the LEDs for any amount of time and they stay lit. The second I turn them off and back on, it resets. Cascading them works fine and they all appear lit.

I still would like to know what is up though. My plans are to drive VFDs with the extender (of course driver circuits added). I just wanted to see how the extender would act. And, as anticipated, not as anticipated.

Probably I should have started with a PicAxe with more outputs. But, I just love that 08M2. I have built so many cool things with it including a great battery charger (lead acid). I attached a picture.
 

Attachments

markdil

New Member
Try bringing the LEDs one one at a time using:

Code:
B4 = 1
FOR B3= 0 to 7
  HI2cOUT (B4)
  PAUSE 1000
  B4 = B4 * 2
NEXT B3
Then watch to LEDs

If it stops after a particular LED then there is a clue.
If LEDs 0 and 1 light up but not 2, then look around the leg of the i2c I/O expander for a short between the pin driving LED2 and that driving LED 3.
Thanks! The first part of my code illuminates the LEDs one at a time. It seems to work fine. I can scan through each LED forward, backward, or from the middle out.
 

westaust55

Moderator
Noting earlier you added 1 decoupling capacitor, try

Put a 100 nF ceramic capacitor across the power supply pins at both the PICAXE and expander chip.
Put a 100 uF (or larger ) Electrolytic capacitor across the power connections near the expander chip.
 

tarzan

Senior Member
A word of caution.

The MAX7320 is rated to sink a total of 100mA and source a total of 50mA from all eight combined outputs.
 

markdil

New Member
A word of caution.

The MAX7320 is rated to sink a total of 100mA and source a total of 50mA from all eight combined outputs.
I am sourcing 70mA. I realized I was a little over. Could this cause the PicAxe to reset? If so, why? Thanks!
 

westaust55

Moderator
Overloading the I/O Expander beyond its rating can cause overheating of that chip and damage to it.

Would not think that would reset the PICAXE chip.
But if the I/O Expander chip pulled the i2c lines low in a high temp "fail" mode, that could/would lock up the i2c bus and disrupt the PICAXE.
 
Last edited:

Goeytex

Senior Member
The MAx7320 is being operated beyond it absolute maximum ratings. This is first thing that should be addressed. The simplest way to do this is to replace the LED current limit resistors. I would use 1K resistors.

If LED brightness is an issue then switch to RED as these are brigher than Yellow given the same limit resistor values or use "high brightness" LEDS. The bottom line here is that the total current (all LEDs On) should not exceed 50 ma if the MAX7320 is sourcing the current or 100 ma if it is sinking the current. Good design practice would be to derate and design for a max current of perhaps 10-20 percent below the absolute maximum.

Use bypass capacitors at both the Picaxe and Max7320. This is not "optional". The MAX7320 datasheet shows a 47nf capacitor in the example circuit. Microchip generally recommends a 100nf capacitor for its microcontrollers.

The above is the bare minimun I would do before testing further.
 

markdil

New Member
That battery charger looks interesting--have you posted any info on it any where?

Thanks
Thanks, I appreciate it. I have not posted anything anywhere.

All the smart chargers out there are not too smart in my opinion. I have worked with batteries for the past 30 years, mostly in electric cars. I own eight electric cars and am infatuated with them.

Anyway, the charger will charge 6 volt, 8 volt, and 12 volt Marine, AGM, or Lead Acid batteries. It is a 5 amp charger, so you can charge up to a 150 amp hour battery with no problem. It uses a LM338 to control the output. I attached a picture of the inside. The 08M2 is on a small board on the left side of the main board. The button is for changing the parameters of the charger, the switch is for changing the current output from 5 amps to 2.5 amps for smaller motorcycle batteries, alarm batteries, and thing like that.
 

Attachments

Top