MCP23016 I/O expander


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Question MCP23016 I/O expander

    I am trying to wire an MCP23016 as output; driving LEDs. No matter what I try, no LEDs light up. Any idea what I am missing?

    ---------------------------------------------------------------
    'define LOADER_USED 1
    ADCON1 = 7 ' A/D off, all digital

    ASM
    @ DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
    ENDASM

    define OSC 20

    DEFINE LCD_DREG PORTA ' Set LCD data port
    DEFINE LCD_DBIT 0 ' Set starting data bit
    DEFINE LCD_RSREG PORTA ' Set LCD register select port
    DEFINE LCD_RSBIT 4 ' Set LCD register select bit
    DEFINE LCD_EREG PORTB ' Set LCD enable port
    DEFINE LCD_EBIT 3 ' Set LCD enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size
    DEFINE LCD_LINES 4 ' Set number of lines on LCD
    define LCD_COMMANDUS 2000 ' Set command delay time in microseconds
    DEFINE LCD_DATAUS 50 ' Set data delay time in microseconds

    DEFINE I2C_SLOW 1 ' Access I2C device above 8MHz
    'DEFINE I2C_SCLOUT 1 ' Set I2C clock line as bipolar
    DEFINE I2C_HOLD 1 ' Permit I2C device to hold clock line low

    I2CSDA VAR PortC.4 ' Data line
    I2CSCL VAR PortC.3 ' Clock line
    I2CCTRL VAR BYTE ' I2C chip address
    I2CLOC VAR BYTE ' I2C location byte
    I2CBYTE1 VAR BYTE ' I2C 8 bit data string
    I2CBYTE2 VAR BYTE ' I2C 8 bit data string

    GOTO START

    ERRORIO:
    LCDOUT $FE,$94,"No ACK from I2C device"
    RETURN

    START: PAUSE 2000 ' Wait for LCD to initalize
    LCDOUT $FE,1,"Program start"

    ' I2C device address: ID A2 A1 A0 R/W
    ' ---- -- -- -- ---
    ' 0100 0 0 0 0

    I2CCTRL = %01000000
    I2CLOC = $06 ' Set location to IODIR register pair
    I2CBYTE1 = %00000000 ' Set pins 0-7 as output
    I2CBYTE2 = %00000000 ' Set pins 8-15 as output
    I2CWRITE I2CSDA,I2CSCL,I2CCTRL,I2CLOC,[I2CBYTE1,I2CBYTE2],ERRORIO
    PAUSE 2000

    I2CCTRL = %01000000
    I2CLOC = $00 ' Set location to GPIO register pair
    I2CBYTE1 = %00101010
    I2CBYTE2 = %00000000
    I2CWRITE I2CSDA,I2CSCL,I2CCTRL,I2CLOC,[I2CBYTE1,I2CBYTE2],ERRORIO

    Finish:
    LCDOUT $FE,$D4,"Process complete"
    end
    ---------------------------------------------------------------


    Yeah, I just noticed an error in my I2CWRITE comment. I meant pins in the sense of logical pins(GP0.0-GP0.7 and GP1.0-1.7).

    I also did some trial & error with the I2C DEFINES, but no luck there. I even increased the PAUSE in case. The program terminates properly, so it seems as if I do get some sort of acknowledgement from the device.

    I've triple-checked the wiring a zillion times. I followed the datasheet and placed the RC as specified.

    I'm stumped...

    Thanks!

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I don't see you initialising this chip. Last I checked it had twelve registers... let's set them up the way you'd like to see them.... then and only then you can perform I/O.

    Have you remembered to GROUND A2, A1 and A0 to match your IOCCTRL Byte?

    Have you remembered to leave TP floating?

    Have you remembered to GROUND all THREE Vss pins?

    Have you remembered Rext and Cext for your external Clock, or alternatively cross-connected it to Fosc of your PIC?

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    "I don't see you initialising this chip. Last I checked it had twelve registers... let's set them up the way you'd like to see them.... then and only then you can perform I/O."

    The default values for all the registers seem to be what I want except for the IODIR register pair. According to the datasheet, we are able to write to both registers in a single write operation. The 1st I2CWRITE is supposed to write all ZEROES to both registers (IODIR0 and IODIR1):

    I2CCTRL = %01000000
    I2CLOC = $06 ' Set location to IODIR register pair
    I2CBYTE1 = %00000000 ' Set pins 0-7 as output
    I2CBYTE2 = %00000000 ' Set pins 8-15 as output
    I2CWRITE I2CSDA,I2CSCL,I2CCTRL,I2CLOC,[I2CBYTE1,I2CBYTE2],ERRORIO

    ----------------------------------------------------------------------

    "Have you remembered to GROUND A2, A1 and A0 to match your IOCCTRL Byte?"

    Yup.

    ----------------------------------------------------------------------

    "Have you remembered to leave TP floating?"

    Yup.

    ----------------------------------------------------------------------

    "Have you remembered to GROUND all THREE Vss pins?"

    Yup.

    ----------------------------------------------------------------------

    "Have you remembered Rext and Cext for your external Clock, or alternatively cross-connected it to Fosc of your PIC?"

    Yup, on the RC connection. I wanted to try your 2nd suggestion, but I can't see an Fosc pin on the 16F877.

    ----------------------------------------------------------------------

    I've even connected all 16 I/O pins to LEDs, so I can easily see what is happening.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Is there any particular reason why MicroChip would NOT include in the datasheet for the MCP23016 a little diagram of pull-up resistors on the data and clock lines?

    Who knows how long this has been working...

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Hmm, I have a feeling the pull-up resistor is more a requirement for the PIC 16F877 than for the MCP23016...

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    4K7 pull-up's ARE required on the I2C lines.

Similar Threads

  1. I/O extender
    By mychangl in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 20th November 2008, 14:56
  2. MCP23016 I2C serial I/O expander chip
    By GeoJoe in forum Serial
    Replies: 7
    Last Post: - 31st October 2007, 15:39
  3. MCP23016 I/O expander with PBP?
    By Jon Chandler in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd August 2005, 09:32
  4. I2C I/O Expander PCF8574 hanging?
    By NavMicroSystems in forum Serial
    Replies: 12
    Last Post: - 4th August 2005, 02:26
  5. managing the I/O ports of the 16F84A
    By skyler_91600 in forum mel PIC BASIC
    Replies: 7
    Last Post: - 28th April 2005, 03:52

Members who have read this thread : 1

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