I am using an nRF52832 to talk to a Melexis MLX90393 (which supports 400kpbs Fast Mode) via the TWIM interface. I am using the TWI Manager library to schedule transactions.
When I choose 400kbps for the TWIM frequency, the SCL line does not clock at 400 kHz (period of 2.5 us) as can be seen in the image below. Instead it is clocking at 200 kHz (period of 5 us).
You can see in the image as well that I am indeed setting the correct value for frequency in the configuration struct passed to nrf_twi_mngr_init(). I have also verified that the FREQUENCY register for the TWIM peripheral (located at 0x40003524) does in fact contain the value 0x06400000.
When I choose 250K or 100K for the TWIM frequency, I indeed see the SCL line run at 250 kHz and 100 kHz respectively.
What can I do to get the 400kbps rate.
Could you try with external pull-up resistors? 400 kHz usually requires around 4.7kOhm pull-ups, as the internal pull-ups are too weak for this mode.
That did the trick! Thank you!
I have just one follow-up question. I plan to put the nRF52832 and two I2C sensors (one of which is the MLX90393 mentioned above) on a custom PCB. Since I now know I need to put external pull-up resistors on the PCB, is 4.7kOhm still a good choice, or would it be a good idea to account for the resistance already there from the internal pull-up resistors that are configured to be active by the driver?
There was a article on this subject of varying i2c resistors, but it has apparently gone down.
I found a pdf'ed version of it here: https://www.thebackshed.com/forum/uploads/BobD/2013-01-26_175209_I2C_-_Effects_of_Varying_Pullup_Resistors.pdf
4.7k is generally a ok value for 400 kHz, you can usually go higher (5.6k) and lower (3.3k) without issues wrt. the wanted frequency.
Thanks, this is great info.