I've been working on an interrupt driven I2C driver. I have the basic driver working, but I'm hoping to squeeze a bit more speed out of it.
I'm mostly doing fairly long transactions, ~10-100 bytes. For one device I do mostly writes and for the other I do mostly reads.
At 400khz a byte takes around 20us and there is a ~4us delay before next byte. The interrupt handler takes about 6us (timed using a gpio) and starts slightly before the falling edge of the the ack clock.
I might be able to shave the interrupt handler down a bit, but it is mostly reading/writing to EVENTS_*, reading from TXD and writing to RXD, there is very little other code in the middle of a transaction. I'm using BB_STOP and BB_SUSPEND shorts to save a PPI channel.
Most I2C devices will happily run faster, so I tried increasing the FREQUENCY register.
100khz is 0x01980000, 250 is 0x04000000, 400 is 0x06680000.
0x07800000 gave me a ~480khz clock some of the time, but other times the clock is more like 240khz with som 480khz clocks mixed in. 0x08000000 should be about ~500khz, but I see mostly a 250khz output.
The part I'm testing with doesn't seem to support clock stretching. I'd imagine what I'm seeing is some sort of weirdness with how the nrf51 synthesizes the I2C clock. Are there any frequency values that will result in a clock that is >400khz?
Any suggestions on how to speed up the TWI interface?