PDA

View Full Version : Controlling MAX7311 port extender



mrx23
- 26th November 2006, 17:48
I want to communicate with MAX7311 port extender.
It has 16 I/O ports. Its uses I2C (max 400 Kbit\s)

http://datasheets.maxim-ic.com/en/ds/MAX7311.pdf

The I2C master is PIC16F628A @ 20Mhz with software I2C.
The job:

TX: Read out the 1st MAX7311 16input ports, transmit to the receiver side with RS232.
RX: receive the message with the 2nd, write the 16bits to the 2nd MAX7311 outputs.

The inteface between the 2 PIC is NOT a problem.
Just the software interface between PIC-MAX7311.

There is the TX side on the picture.
http://kepfeltoltes.eof.hu/files/83_431164563466.png

The extenders I2C address is: 0x40 (64 dec).
CLK:PB3, DATA:PB2

'-----------
switch VAR byte[2]

I2Cread PORTB.2,PORTB.3,0,64,switch[0],switch[1]
'Control=0, Adr=64, store received 2 bytes in switch

'-----------

switch VAR byte[2]

I2Cwrite PORTB.2,PORTB.3,0,64,switch[0],switch[1]
'Control=0, Adr=64, set

'-----------

Is this going to work?
START, STOP, and acknowledge bits are automatical controlled by I2Cwrite/read command?

How do I set the 2nd MAX7311's Port1/Port2 registers to output?

Thank you!

Darrel Taylor
- 26th November 2006, 21:57
It's a bit confusing, isn't it?

The expanders "address" goes in the I2C Control byte, and the "command" goes in the Address byte.

Read Input Ports:
I2Cread PORTB.2,PORTB.3,64,0,[switch(0),switch(1)]

Write Output Ports:
I2Cwrite PORTB.2,PORTB.3,64,2,[switch(0),switch(1)]

Set Port Configuration:
PE_TRIS VAR BYTE[2] ; bitwise - 1=input 0=output
PE_TRIS(0) = 255    ; Port1 all input
PE_TRIS(1) = 0      ; Port2 all output

I2Cwrite PORTB.2,PORTB.3,64,6,[PE_TRIS(0),PE_TRIS(1)]

How do I set the 2nd MAX7311's Port1/Port2 registers to output?For a second Expander, you would tie pin <strike>AD1</strike> AD0 to Vdd to change it's slave address to 66. Then you can use it just like the first one.

Read Input Ports:
I2Cread PORTB.2,PORTB.3,66,0,[switch(0),switch(1)]

Set Port Configuration: (all output)
I2Cwrite PORTB.2,PORTB.3,66,6,[0,0]

HTH,

mrx23
- 26th November 2006, 22:20
Thank you very much!!!

How can MAXIM swap the Control Byte and a Address byte order?
Isn't that standard?

If I want the 66 slave address (that is 0x42), I will have to set like this:
AD2 GND
AD1 GND
AD0 Vdd

SteveB
- 26th November 2006, 23:13
How can MAXIM swap the Control Byte and a Address byte order?
Isn't that standard?

In reality, nothing is "swaped", its just that PBP has chosen to label the bytes in their software I2C in a "non-standard manner". This is because they use the labels used for EEPROMs. (worth looking at a datasheet)

I2CREAD DataPin,ClockPin,Control,{Address,}[Var{,Var...}]{,Label}

As listed, Control is the first byte sent. Bit 0 of this byte controls the direction of communication, either a read or write operation. In many I2C devices, the first byte sent, with bit 0 as the R/W bit, is called the slave address (but not with EEPROMs).
Address is also confusing, since PBP uses this to refer to the internal register address being accessed in the device, not the actual bus address of the device. It will be the byte/word sent after the slave-address/control byte, and is called different things based on the device, but "command-byte" or "control-byte" are common. (but not with EEPROMs)

You definately need a good understanding of the I2C protocol to translate PBPs I2C commands to a device other than an EEPROM



If I want the 66 slave address (that is 0x42), I will have to set like this:
AD2 GND
AD1 GND
AD0 Vdd
Yes, it looks that way to me. :D

Hope this clears it up a little more,
Steve

Darrel Taylor
- 27th November 2006, 00:07
Caught me with a typo :o

I also want to mention that you shouldn't have the 2 - 1.0K resistors between the two chips.

All you need are the 2 - 4.7k pull-ups.
<br>