This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI speed not correct

Hello DevZone,

I was tinkering around with the speed of the TWIM0 module in the nRF52832.

I have a cheap USB logic analyzer to help me display the waveforms and I made a discovery.

Testing the TWIM0 with 100kbps results this:

Perfect 100kHz clock signal.

Testing the TWIM0 with 250kbps results this:

Uneven duty cycle 250kHz clock but still spot on.

Testing the TWIM0 with 400kbps results this:

Euh.. Wait, that's a 200kHz signal, how is this possible. TWI isn't ment to do double data rate :)

Checking out the datasheet on the clock rate I see that at 400kbps the frequency value should be 0x06400000. Looking in the nrf52_bitfields.h I see that the 400kbps clock is defined as #define TWI_FREQUENCY_FREQUENCY_K400 (0x06680000UL) /*!< 400 kbps (actual rate 410.256 kbps) */

Writing the datasheet value of 0x06400000 does not change the frequency to 400kHz but  slightly lower than 200kHz.

I've tested some different values to see what output frequency I get and this is what I got

0x01000000 -> 62.5kHz
0x08000000 -> 250kHz
0x08880000 -> 266.67kHz
0x0A880000 -> 333.33kHz
0x0C880000 -> 400kHz
0x10000000 -> strange waveform at 500kHz
0x20000000 -> unstable waveform at 1MHz (could be that my slave could not keep up properly.
0x40000000 -> 666.67kHz

Is anyone able to explain this to me? Could this be a silicon bug as I did not test it on a other nRF52832?

Is there any information how this variable is handled within the TWI module and how it is possible to get frequencies which are out of spec from the nRF52832?

Kind regards,

T IJ

Parents
  • I've had a similar issue. I think I found the source of the issue: the chip's TWIM clock stretching. I'm unfamilar of how the internal chip circuitry works, but I noticed when I added a longer wire to my circuit, all of a sudden the clock rate went from 250kHZ to 125kHz (with the master frequency set to 250kHz). Just by adding a wire! The additional capacitance must have some effect on the clock stretching circuit.

    Just speculating, but the theory would be the slow rise times fool the TWIM into thinking a peripheral is clock stretching, so the TWI skips a clock cycle until the clock line rises back again.

    For workarounds, try using a larger pull-up resistor.

  • Excellent thinking, most helpful and may explain issues we have also seen; I used a different divisor matching that of the uart, but this seems like a better underlying cause. The discussion I had with olfox s here under twi

Reply Children
No Data
Related