It's my first post in this forum. :D
I 'm working on a project using psoc 3 cooperating with my colleague. A I2C component is used as an I2C slave to communicate with another hardware. This is my task. The chip has other tasks in main process and that is implemented by my colleague. In this project, the other hardware (I2C master) will cyclically read from I2C slave, let's say about every 50 ms. For testing, I programmed a second psoc 3 chip as a test I2C master (It's only for testing, in the end the master will not be a psoc chip). The master chip is connected with PC through serial port and user can send bytes as command from HTerm in PC to the master chip. A UART component in chip will interpret the received command and then decide if I2C master will read or write from I2C slave. A Timer is used so that the master can read cyclically. An example of HTerm command can be 0x52 0x00 0x04 0x50 ('R', slave buf addr to start reading, num of bytes to be read, 'P' ). Please ignore the big pile of spaghetti in master code, I find it quite dirty but it's only for a quick test. In slave side, I have seen some examples and all of them do the status check, buffer preparing etc. in a loop in main(). But I cannot do this in my case because the main loop is for other tasks. So I put everything into isr callback functions.
/* End of the loooooong background story */
After several times testing, I found out a problem. The slave halts sometimes because it reaches unexpected condition in isr (line 509 in file I2C_Slv_INT.c). And the signal in oscilloscope shows that the I2C slave interrupts before it receives a complete byte. I guess that it is because the bit counter not cleared properly(I actually didn't know about bit counter till I saw codes about it in I2C_stop()). My current solution is calling I2C_stop() and I2C_start() API functions to clear everything up and start again.
My question is:
1. Is bit counter the real reason that cause my problem?
2. Is it expensive to stop and start the component again?
3. Are there other solutions?
4. I guess there are things I can do to optimize I2C slave isr. Could someone please give me some advise?
Thanks in advance,