AnsweredAssumed Answered

I2C hot plugging issue

Question asked by László Monda on Feb 4, 2017
Latest reply on Apr 6, 2017 by László Monda

Hi there,

 

I'm working on an unusually complicated keyboard, the Ultimate Hacking Keyboard.

 

The keyboard halves are connected via I2C, driven at 100 kHz. The right keyboard half (K22) is the master device and it talks to the left keyboard half (KL03) all the time in order to keep the state up-to-date as much as possible.

 

This is working well, except when I disconnect the keyboard halves and reconnect them. I want to make the communication resume then which doesn't always happen.

 

I use `I2C_MasterTransferNonBlocking()` to kickstart the communication between the keyboard halves, then I use it again at the end of my I2C callback to keep the communication going. The problematic part is when the keyboard halves get separated.

 

This is my simplified callback:

 

 

static void i2cCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t status, void *userData)

{

    if (status != kStatus_Success) {
        I2C_MasterDeinit(I2C_MAIN_BUS_BASEADDR);
        I2C_MasterInit(I2C_MAIN_BUS_BASEADDR, &masterConfig, sourceClock);
        I2C_MasterTransferCreateHandle(I2C_MAIN_BUS_BASEADDR, &masterHandle, i2cCallback, NULL);

    }
    status_t status2 = I2C_MasterTransferNonBlocking(I2C_ADDRESS, &masterHandle, &masterXfer);

}

 

As you can see above, I check the status variable of the callback and try to reset the state of the I2C peripherial to keep the communication going. If the status is not success, I deinitialize, then reinitialize I2C, then recreate the handle.

 

I've already spent hours on making this reliable but even the current code is not good enough. The communication stops after a couple disconnects, and sometimes the state of the master gets screwed too, to the point that the right keyboard half doesn't scan the keyboard matrix anymore, which is weird because it's totally unrelated to the I2C callback.

 

I'd really appreciate any help on this issue.

 

Thank you,

- Laci

Outcomes