MCP23017 init & data transfer

ChibiOS public support forum for topics related to the Freescale Kinetis family of micro-controllers.

Moderator: utzig

Posts: 1
Joined: Mon Jan 22, 2018 10:10 pm

MCP23017 init & data transfer

Postby ravnicas » Mon Jan 22, 2018 10:19 pm

hi, im hoping to find some help with i2c init on a teensy 3.2. I tried searching, but couldnt find the source of my problem.

Im trying to init an MCP23017 expander. The controller halts as soon as i start the data transfer. the goal is to set GPIOA1 to HIGH.
Maybe someone already had this problem, or could guide me to an answer. That would really help me.

Code: Select all

uint8_t init_mcp23017(void) {
    mcp23017_status = 0x20;

    i2cStart(&I2CD1, &i2ccfg);

    tx[0] = 0;
    tx[1] = 0;

    i2cMasterTransmitTimeout(&I2CD1, 32, tx, 2, rx, 0, 100);
   tx[0] = 20;
   tx[1] = 1;
   i2cMasterTransmitTimeout(&I2CD1, 32, tx, 2, rx, 0, 100);

    return mcp23017_status;

Posts: 7
Joined: Fri Dec 08, 2017 6:52 am
Location: Seattle, USA
Has thanked: 2 times
Been thanked: 5 times

Re: MCP23017 init & data transfer

Postby wiml » Thu Feb 08, 2018 8:57 am

Do you have a pullup on the i2c lines? On the Kinetis parts, if you need a pullup but don't have an external pullup, I think you need to explicitly enable pullups on an open-drain pin (I don't think the PAL driver can do this, you need to do it explicitly). The i2c peripheral might be hanging because it interprets a low clock line as i2c "clock stretching".

Posts: 1
Joined: Sun Oct 21, 2018 10:53 pm

Re: MCP23017 init & data transfer

Postby FromtonRouge » Sun Oct 21, 2018 11:24 pm


Any news on this one ? I have the exact same problem here but with a MCP23018 expander (and I also use a Teensy 3.2). I ended up with a similar code as the OP (that's why I found this post)

Code: Select all

    i2cStart(&I2CD1, &i2c_config);
    tx[0] = MCP_IODIRA;
    tx[1] = 0b01111111;
    i2cMasterTransmitTimeout(&I2CD1, MCP_I2C_ADDR_WRITE, tx, 2, NULL, 0, MS2ST(500));

The timeout (500 ms) is triggered then the I2C driver is in LOCKED state (I2CD1.state = I2C_LOCKED)
I have external pullups on SDA and SCL (2.2 kOhms). The circuitry seems to work because I did a simple test in Arduino and the Wire library and it worked well. Now I want to do the same test but with ChibiOS.

I can't find a working example of I2C for the Teensy 3.1/3.2 in chibios-contrib/testhal/KINETIS/TEENSY3_x am I missing something?

Return to “Kinetis Support”

Who is online

Users browsing this forum: No registered users and 1 guest