AnsweredAssumed Answered

Possible bug in the MQX i2c Slave-mode driver code

Question asked by Wade Miller on Nov 16, 2010
Latest reply on Sep 19, 2011 by Aaron Linsdau

I have been trying to get a slave-mode i2c driver working in MQX, running on an MCF52259.  During the process, I encountered what I think is a bug.


I am using MQX v3.6.0, but I've verified this bug still exists in the latest v3.6.2 code.  The offending code is on line 600-ish of the 'i2c_int_mcf52xx.c' module:


 /* Receive requested */
if (((I2C_STATE_RECEIVE == io_info_ptr->STATE) || (I2C_STATE_ADDRESSED_AS_SLAVE_RX == io_info_ptr->STATE)) && (0 != io_info_ptr->RX_REQUEST))
    // find! WAM -- bug: assign RX_IN + 1, NOT post increment, or else we always fall into
    //                   the "tmp == io_info_ptr->RX_OUT" conditional and disable INTs.
    tmp = io_info_ptr->RX_IN + 1;
    //tmp = io_info_ptr->RX_IN++;
    if (tmp >= io_info_ptr->INIT.RX_BUFFER_SIZE) tmp = 0;
    if (tmp == io_info_ptr->RX_OUT)
        i2c_ptr->I2CR &= (~ MCF52XX_I2C_I2CR_IIEN);



You can see the (original) line of code I commented out above, and replaced with the line in red.  That modification actually came directly from the same algorithm in the master-mode code block higher up in the file.


I'm not sure if this forum is the most appropriate place to post bugs or not, but at least it may help the next person trying to use this driver in slave-mode.


Once I made that change, the driver began to accept characters from the master as expected.