Hello,
I am using a timer interrupt to calculate a buffer of 32bytes, and then serving this buffer as i2c slave. The problem is from time to the i2c call from master intervenes with the calculation of buffer, i.e. i start reading tru i2c while the buffer is being formed.
Of course this is a generic programming problem, and I am aware of my options. But however, it is not possible to have i2c interrupt handler waiting, so is there a way to cancel the i2c read callback if a semaphore is busy?
I have an I2C slave handler like:
void I2C0SlaveIntHandler(void) { // clear data interrupt HWREG(I2C0_BASE + I2C_O_SICR) = I2C_SICR_DATAIC; bool _stop = false; if(HWREG(I2C0_BASE + I2C_O_SRIS) & I2C_SLAVE_INT_START) { // clear start interrupt HWREG(I2C0_BASE + I2C_O_SICR) = I2C_SICR_STARTIC; // set indices to 0 writeIndex = 0; statusIndex = 0; resultIndex = 0; ledIndex = 0; } else if(HWREG(I2C0_BASE + I2C_O_SRIS) & I2C_SLAVE_INT_STOP) { // clear stop interrupt HWREG(I2C0_BASE + I2C_O_SICR) = I2C_SICR_STOPIC; _stop = true; }
If my main timer loop is busy executing calculations, is there any way I can hold the i2c request from master waiting until the calculations are complete, or even is it possible to return an error, or some sort of indication so the master can re-request the packet?
How would you approach this problem. Basically I have an timer loop, doing some work, and I read it with i2c, externally asynchronously.
Best Regards,
C.A.