Shop OBEX P1 Docs P2 Docs Learn Events
MCP23017 configuring reading and writing remote IO — Parallax Forums

MCP23017 configuring reading and writing remote IO

Helo for all

I am trying to run the MCP23017Driver Erlend Fj. 2015 object but it didn´t execute the code line: value:= bus.CallChip(Chip<<1) - (line 81).
It stop in line 79. I would like to know how I solve that.
Thanks in advance.

Comments

  • You might consider posting the code giving you trouble -- not everyone has all objects (I don't have any by Erlend).

    I haven't used this driver in a long time and I don't have an MCP23017 to test with, but you're free to give it a go. I also included an I2C bus scanner project that can help you verify connections.

  • @JonnyMac said:
    You might consider posting the code giving you trouble -- not everyone has all objects (I don't have any by Erlend).

    I haven't used this driver in a long time and I don't have an MCP23017 to test with, but you're free to give it a go. I also included an I2C bus scanner project that can help you verify connections.

    Thank you very much Jon
    I will test it and surelly it will be very mach instructive.
    Thank you again

  • I know nothing about the driver but you do have the addressing set-up correctly, right?

    In BASIC, for example:

     const mcp23017 = &h20 ' A2, A1, A0, R/W all connected to 0V
     const i2caddr=mcp23017
    

    Craig

  • JonnyMacJonnyMac Posts: 9,157
    edited 2023-09-06 16:10

    In my driver the device type is pre-defined -- and already left-shifted to accommodate the R/W bit (which is why my address is $40 vs $20)

    con
    
      MCP23017 = %0100_000_0                                        ' I2C device ID for MCP23017
    

    From the MCP23017 datasheet:

    Calls in my driver include the device address bits; that way you only need one object to deal with up to eight MCP23017s (I've only ever used two in a project).

    pub rd_reg(reg, addr) : value | id
    
    '' Read value from register in device at addr
    '' -- see constants section for valid registers
    '' -- see MCP23017 docs for details on register value
    '' -- addr is device address, %000 to %111
    
      id := MCP23017 | (addr << 1)                                  ' id for write
    
      i2c.start                                                     ' start transaction
      i2c.write(id)                                                 ' write id
      i2c.write(reg)                                                ' write reg #
      i2c.start                                                     ' re-start
      i2c.write(id | %1)                                            ' id for read
      value := i2c.read(i2c#NAK)                                    ' read value from reg
      i2c.stop                                                      ' end transaction
    
  • Here is a code snippet for the MCP23s08. The MCP23s17 is a little different and the MCP2308 is totally different. Hope this helps though.
    It has been awhile since I used this, so you are on your own. Best.

Sign In or Register to comment.