I am writing a I2C2_IRQHandler and cannot get it to work without accessing the FIO banks. I can see it work perfectly in the oscilloscope when I include any FIO access. Even if the gpio access does nothing at all but read a register and do nothing with the result - that seems to be enough to make it happy. As soon as I remove it all I get is a start transmission and then NOTHING. Its like the SI bit isn't getting cleared anymore.
My code can be found at blueboard/i2c.c at master · benjaminjnoack/blueboard · GitHub
已解决! 转到解答。
I solved it! I was attempting to write to the I2DAT register before clearing the SI bit. From the user manual:
This register contains the data to be transmitted or the data just received. The CPU can
read and write to this register only while it is not in the process of shifting a byte, when the
SI bit is set. Data in I2DAT remains stable as long as the SI bit is set.
I solved it! I was attempting to write to the I2DAT register before clearing the SI bit. From the user manual:
This register contains the data to be transmitted or the data just received. The CPU can
read and write to this register only while it is not in the process of shifting a byte, when the
SI bit is set. Data in I2DAT remains stable as long as the SI bit is set.
I've discovered a few things since my first posting.
It doesn't have to be FIO access; I can put a printf statement at the bottom of the IRQ and it will work fine. If I remove the print statement then I just get the start condition again. Even stranger, the length of the print statement affects how much of the I2C message is transmitted or received! If the print message is just a newline character then it works great, my test program of sending or receiving 5 bytes works perfectly. If the print message is "hello" then I only get half of the message. If the print message is "hello world" then I only get two bytes of it. Extremely bizzare! There is something I'm not seeing...