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

Correct TWI Sensor data only when programmer connected

Hello,

I have made a custom board using nrf51822 QFAC that has an IMU on TWI interface. For programming I am using ST-LinkV2 and OpenOCD. The board is working just fine. I have successfully programmed it.

I want to transmit the readings from the IMU (rotation angles on each axis x, y and z). For this I have made a custom service with a read-only characteristic where I put the readings from the sensor. The notification property is enabled. Everything is ok, the service gets created and the characteristic is present just as I have configured it. I am using nRF Connect on Android to read the characteristic.

For reading the sensor I have made a library that use APP_TWI, just as I have seen in the examples from SDK v12.2.0. While writing this library I have checked every single one return value of the app_twi_perform function, and I advance in the code only if I get NRF_SUCCESS.

In the main loop, on every iteration I read the sensor and update the characteristic.

The Problem: if I let the ST-LinkV2 (plugged in usb) programmer connected to my board, after flashing, the results are ok - the characteristic gets updated and I can see the angles in nRF Connect. If I unplug the programmer from my custom board after flashing, the characteristic in nRF Connect is 0. All angles are 0.

I do not understand the link between the SWD interface and TWI. Why when SWDIO, SWDCLK and GND are connected to ST-LinkV2 the data from the sensor are correct, and when they are disconnected why do I get 0?

In order to identify that the problem is with TWI, I have made a variable I increment every iteration and I update the characteristic with this variable, instead of the values read from the sensor. The result: the characteristic gets updated no matter what the state of the SWDIO, SWDCLK pins is (ST-Link connected or disconnected). I can see the variable value gets incremente in nRF Connect.

Related