diff --git a/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c b/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c index 55554a788b..32223b10f7 100644 --- a/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c +++ b/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c @@ -1531,9 +1531,36 @@ void MXC_I2C_RevA_SlaveAsyncHandler(mxc_i2c_reva_regs_t *i2c, mxc_i2c_reva_slave } } + // Check if transaction completed or restart occurred + if (int_en[0] & MXC_F_I2C_REVA_INTFL0_DONE) { + if (tFlags & MXC_F_I2C_REVA_INTFL0_STOP) { + // Stop/NACK condition occurred, transaction complete + *retVal = E_NO_ERROR; + + if (callback != NULL) { + callback(i2c, MXC_I2C_REVA_EVT_TRANS_COMP, retVal); + } + + i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_STOP; + int_en[0] = 0; + int_en[1] = 0; + AsyncRequests[MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c)] = NULL; + } else if (tFlags & MXC_F_I2C_REVA_INTFL0_DONE) { + // Restart detected, re-arm address match interrupt + i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_DONE; + int_en[0] = MXC_F_I2C_REVA_INTFL0_ADDR_MATCH; + } + } + // Check for address match interrupt if (int_en[0] & MXC_F_I2C_REVA_INTFL0_ADDR_MATCH) { if (tFlags & MXC_F_I2C_REVA_INTFL0_ADDR_MATCH) { + // Address match occurred, prepare for transaction + if(tFlags & MXC_F_I2C_REVA_INTFL0_STOP && !(tFlags & MXC_F_I2C_REVA_INTFL0_DONE)) { + // Clear stop flag if it was asserted in a previous transaction + i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_STOP; + } + if (i2c->ctrl & MXC_F_I2C_REVA_CTRL_READ) { // Read request received from the master if (callback != NULL) { @@ -1561,27 +1588,6 @@ void MXC_I2C_RevA_SlaveAsyncHandler(mxc_i2c_reva_regs_t *i2c, mxc_i2c_reva_slave } } } - - // Check if transaction completed or restart occurred - if (int_en[0] & MXC_F_I2C_REVA_INTFL0_DONE) { - if (tFlags & MXC_F_I2C_REVA_INTFL0_STOP) { - // Stop/NACK condition occurred, transaction complete - *retVal = E_NO_ERROR; - - if (callback != NULL) { - callback(i2c, MXC_I2C_REVA_EVT_TRANS_COMP, retVal); - } - - i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_STOP; - int_en[0] = 0; - int_en[1] = 0; - AsyncRequests[MXC_I2C_GET_IDX((mxc_i2c_regs_t *)i2c)] = NULL; - } else if (tFlags & MXC_F_I2C_REVA_INTFL0_DONE) { - // Restart detected, re-arm address match interrupt - i2c->intfl0 = MXC_F_I2C_REVA_INTFL0_DONE; - int_en[0] = MXC_F_I2C_REVA_INTFL0_ADDR_MATCH; - } - } } void MXC_I2C_RevA_AsyncHandler(mxc_i2c_reva_regs_t *i2c, uint32_t interruptCheck)