This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Possible bug in TWI HW

Hi

I'm having a strange behaviour when using the TWI HW peripheral for reading from an I2C device. My application tries to read one byte from a register in a I2C device. As background:

-I2C address: 0x55 -Register address: 0x0A -Expected value: 0x10 -I2C speed: 50KHz (very slow: at higher rates more errors)

The problem is that when reading, I've detected that the first SCL pulse I sent when starting to receive the register data has a variable width. Normally, there's no problem because its width is wider than normally, but sometimes (1/10) its witdh is smaller than 4us. When this happens, the I2C device doesn't recognize this pulse as a SCL pulse, so the received data is shifted one position. In other words: when expecting 0x10, i get 0x08.

In the first image, you can see a successul data transaction. scope_0.bmpimage description

The second image is a zoom over the first SCL pulse when receiving the data register. You can see this pulse is wider than the following ones. scope_2.bmpimage description

In the third image, its width is now 3.4us, causing the problems. scope_4.bmpimage description

To try to debug this problem, I've disabled the SD, and my SW is inside a while (1) and only reading this register. Only the TWI peripheral is enabled.

I've no found errata references and no similar problems in this forum. Am I getting crazy?

Any guess?

Thanks in advance

Cheers,

Elena

  • I had trouble with TWI + softdevice and found this forum posting to be very useful:

    devzone.nordicsemi.com/.../

    In Stefan's answer you'll find a link to twi_hw_master_sd.c. I had trouble with link failures using twi_hw_master.c from the 6.0.0 SDK, these problems cleaned up after switching to the _sd version.

    I do still see some apparent clock mis-behavior, but it appears as a shortened clock low time associated with a NAK:

    image description

    The TWI master configured for 250 kHz operation, this shows an attempted access to a slave device that is not present. Fortunately the 1.1 us clock low time is well above the minimum clock low time for our slave devices and this isn't causing any problems.

    If you are not already using it, you might try twi_hw_master_sd.c. I started a test yesterday that accesses a TWI slave every 100 ms under timer/scheduler control. TWI interface and BLE stack both survived the night.

    Best Regards and Good Luck!

    Matt

  • Hi MatBB

    I desisted about using the TWI peripheral and now I'm using the TWI SW to implement an I2C bus by using two GPIOs. Now it is working correctly.

    Thanks for your help

Related