Controlling MAX7311 port extender


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2005
    Posts
    19

    Default Controlling MAX7311 port extender

    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!

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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,
    Last edited by Darrel Taylor; - 26th November 2006 at 23:33. Reason: Fixed AD0 Typo
    DT

  3. #3
    Join Date
    Sep 2005
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mrx23
    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


    Quote Originally Posted by mrx23
    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.

    Hope this clears it up a little more,
    Steve

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Caught me with a typo

    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>
    DT

Similar Threads

  1. Why (or how to) make a port array for OW
    By Roy___ in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 22nd February 2009, 23:30
  2. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  3. port config.
    By tamertokgoz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th July 2008, 12:25
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. STATUS re-curtain W
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th February 2005, 15:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts