TWIM driver issue with LSM6DS3TC-R

Hi,

I need to read out the Gyro Data of an LSM6DS3TC-R via I2C/TWI. The xiao nrf board uses an nrf52840 and has the gyro sensor build into it, so I don't have access to the pins with an oscilloscope. I know the connection as it is drawn in the schematic I attached is working, because with the original bootloader by xiao with their own i2c library it is working fine.

There is a little problem I want to point out first: The TWIM driver returns immediately with NRF_SUCCESS when starting a transfer with nrfx_twim_xfer() with the NRFX_TWIM_FLAG_NO_XFER_EVT_HANDLER flag enabled. I don't know if that is intended or not, but for me it seems more reasonable to not use the event handler with that flag set, even though during initialisation an event handler was specified.

Now the second problem: When trying to initialise the sensor by reading out the so called "WHO_AM_I" register, sometimes the TWIM driver hangs itself in the nrfx_twim_xfer() function because no event is being set, after the TXSTARTED event. When debugging after the program is stuck in that loop of event checks, lines 538, 544 and 551 of nrfx_twim.c file. I did not manage to reproduce that error in a certain way, sometimes it occurs, sometimes it doesn't and the sensor is working fine, with exactly the same code.

I already tried using the nrfx_twi driver instead or even the nrf_drv_twi but the results were similar. The twi_scanner example sometimes works and sometimes doesn't work, as it hangs itself in the same part of the code. I also tried manually resetting the i2c bus with the nrf_twim_twi_bus_recover function before initialising the twi driver, but that also doen't change anything. I also tried to clone the xiao "Wire_nRF52" lib from the original bootloader but even that resulted in the same problems.

The pins used internally for the Sensor are P0.07/SDA and P0.27/SCL and P0.07 is also used for TRACECLK, is that maybe the problem? Because the only difference there is anymore, is that the original bootloader uses no debugging via the J-Link, but has dfu enabled for the Arduino IDE.

The code I wrote is quite much by now, but if it helps, I could also post it.

I am using: Segger Embedded Studio v5.42a, nRF SDK 17.1.0, Softdevice S212 7.1.0 on an XIAO nRF52840 BLE Sense with a J-Link to flash via SWD.

I am thankful for every answer that could help... Thanks in advance!

Parents
  • It is a bit difficult to say what is wrong, but the loop in which it is stuck seems to say that the transfer was initiated and none of the events occurred in the hardware. Without oscilloscope data we can only guess few things.

    1. If you suspect if it has something to do with NRFX_TWIM_FLAG_NO_XFER_EVT_HANDLER enabled, then disable it and give the proper event handler just for testing.
    2. Try to debug this with logs/prints and not using TRACECLK if you suspect this could be issue. If the program behaves differently in debug mode and in normal mode, then it is likely that it has to do with shared pins with debug interface.

  • Hi,

    yes, the problem definitely is that of the three TWIM events that are checked occurs. I already tried it without the no event handler flag, and also in debug vs release mode - no difference in behaviour. I even tried to check the ERRORSRC Register in the twim driver as well, but neither the ANACK nor the DNACK bit is set. Also Logging basically everything shows the same result.

    I am not using the TRACE lines - even checked the nrf.h file for the project in SES, but everything seems to be initialised (deactivated) correctly.

    The problem with oscilloscope data is, that the gyro sensor is not accessible on the xiao board. I thought of routing the gpios to other ones via PPI, to simply mirror the SCL and SDA lines to other pins that are accessible with the oscilloscope. Could that work or does the SDK/hardware not allow such functionality?

    Best regards!

  • Fabian,

    You should e able to configure the GPIOTE in event mode and make it listen to the TWI pins to generate events. You can use these events to route it through PPI fork TEP to change another gpio pin to toggle the same way as the first input pin to GPIOTE. 

  • I will try that later, I don‘t have time at the moment. For the GPIOTE in event config I have to use the RAW config macro to not change the pin config of the twim driver?

    - Fabian

  • yes, you cannot change the TWIM driver config but to use gpiote api

Reply Children
No Data
Related