Hi again,
I'm gratified to see lots of i2c questions here on the forum. Fortunately there are some good examples of using master mode, especially polling the hardware. The search function becomes really useful for that.
I'm writing a Tiva i2c library because I have spent countless hours debugging the Tiva i2c hardware. I feel like I'm starting to achieve a good understanding of the master mode side of things, so I wanted to make that a package that can be reused by you all.
Slave mode is the missing piece. Yes, I can respond to I2C_SCSR_TREQ and the slave transmits fine. That's as far as I can get. Then I hit questions I can't seem to answer: (see the source code link at the bottom)
1. In example-isrnofifo.c: if I change i2c2.ti2cit.len = 0 to sizeof(write_buf) on line 109 then instead of just a QUICK_COMMAND it actually writes one byte before reading (using a repeated START). The slave controller never asserts I2C_SCSR_RREQ in either case, it just adds an additional I2C_SCSR_TREQ. This is probably the heart of the problem -- why am I getting 5 (or 6) TREQ instead of 1 (or 2) RREQ followed by 4 TREQ?
2. In example-isrnofifo.c: If I uncomment I2C_MIMR_STARTIM on line 223, the slave receives no interrupts other than STARTRIS.
3. In example-isrnofifo.c: If I uncomment I2C_MIMR_STOPIM on line 223, the slave receives no interrupts other than STOPRIS -- and it gets 2 STOPRIS when I am sure I am only sending one i2c STOP. (If both are unmasked then the slave receives one START and one STOP.)
4. In example-isrnofifo.c: The SCSR never sets QCMDST or QCMDRW, lines 305 and 320.
5. In example-isrnofifo.c: If I uncomment I2C_MCR_LPBK on line 215, just in case the problem is because I am using the device in loopback mode without setting that bit, I see no difference in the interrupt behavior. I do have a device which reports temperature on the bus, which is why I have been commenting out I2C_MCR_LPBK.
6. If I uncomment I2C_MCR_LPBK as above and also comment out GPIO_O_PUR) |= GPIO_PIN_0 | GPIO_PIN_1 in example-main.c line 102 I see no difference in the interrupt behavior.
Thanks in advance for helping me debug my i2c slave code!
Test cases uploaded to https://github.com/davidhubbard/tiva-ussh/tree/master/libti2cit - run the app then choose 2 from the menu presented on UART0 (2. Interrupts)
P.S. As to why I titled the post tiva-pirate: I'm definitely hoping to make this library the go-to solution for Tiva i2c code, including the tiva-pirate bus pirate clone.