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.

Parents
  • Okay, I have found the problem.

    The IMU I am using accepts an external 32kHz crystal oscillator for better performance instead of the internal one. When I was initializing the TWI and my sensor I was configuring it to use external crystal. Now I have configured it to use the internal one and it works perfectly (with or without OpenOCD open/with or without ST-LinkV2 connected).

    I do not understand why it works with the external crystal for IMU only with OpenOCD running. Any ideas what could be the connection between those two is welcome. The wires I connect to the programmer are: SWDIO, SWDCLK and GND. No VCC - the board is powered from batteries.

    I will be using the internal oscillator but I will still investigate the problem. If I find anything I will let you know.

  • nRF51822 and IMU have each their own 32kHz oscillator. The only thing these two oscillators have in common is GND.

Reply Children
No Data
Related