I am doing a test program on LPC2292 processor.
There are three tasks running. TaskA and TaskB may want to read/write data on another device through I2C interfaces at some point. The two tasks can call my I2CRead and I2CWrite functions and then call the callback functions after the I2C network transaction is done. When TaskA and TaskB individually call the I2C functions, everything works OK. But when TaskA is keep reading slave device register every second, TaskB trying to write one byte to the slave device may blow up the processor.
I tried to use the resource management API(xSemaphoreCreateCounting), but it didn’t help. I am thinking probably because something goes wrong when TaskB try to write a byte while the I2C read is not finished in TaskA. TaskB has a higher priority than TaskA.
Do I need a semaphore in I2C ISR when the I2CRead is finished, to inform the task?
Could it solve the problem if I use xSemaphoreTake and xSemaphoreGive in TaskA/TaskB before calling I2CRead and I2Cwrite?
Is a third task, like I2CTask needed? So every time when TaskA/TaskB want to get access to the I2C interface it will wake up the I2CTask and let the I2CTask do its job.
Thanks in advance!