RPi Pico / LSM6DS3TR-C IMU over SPI works only if scope probe is connected!? - Page 1
Forum section: electronics / projects

author: mrmp17
author_rank: Contributor
timestamp: March 15, 2024, 11:00:15 am
content: I'm trying to interface a LSM6DS3TR-C 6-dof IMU with a Raspberry Pi Pico / RP2040. IMU is on the Adafruit breakout. Cables are <10cm long, soldered directly on both sides. I'm using pins 16-19 on Pico. My code is just polling the IMU's WhoAmI register periodically.Here is the issue: IMU only responds to the register read if at least two oscilloscope probes are connected to SPI data lines. If not, MISO just stays low. When exactly it works does change with SPI clock, time of the day and probably the weather, but I have not found it to be more reliable at lower clocks. The register read data packet looks perfect otherwise, as per datasheet. I also tested the IMU with FT232HQ USB-SPI bridge - works perfectly and the WhoAmI read looks basically identical on the scope to what I see with the Pico.The breakout has some level shifters, so I tried connecting my data lines directly to the IMUs pins, which changed exactly nothing - still works omly sometimes, mostly when two or more scope probes are connected. I don't see how scope could affect the signals - it certainly does not look like some lines are floating and being pulled low by scope - the edges are way too quick for that (around 20ns on CS for example).Honestly, I have absolutely no idea what is happening. Any guesses?Here is the code (platformio with arduino core) and a scope screenshot of CS (pink), MOSI (blue) and CLK (yellow) lines with signals connected directly to IMU and the probes close to the IMU. In this example, I got a valid WhoAmI reply, because the probes were connected...Code:#include <Arduino.h>#include <SPI.h>#define cs 17uint8_t read_register(uint8_t addr) {addr |= 0x80;uint8_t out = {addr, 0xFF};uint8_t in;digitalWrite(cs, LOW);// delay(1);SPI.beginTransaction(SPISettings(1000000UL, MSBFIRST, SPI_MODE0));SPI.transfer(out, in, 2);SPI.endTransaction();// delay(1);digitalWrite(cs, HIGH);return in;}void setup() {// put your setup code here, to run once:pinMode(cs, OUTPUT);digitalWrite(cs, HIGH);Serial.begin(115200);delay(1000);Serial.println("Hello World");SPI.setRX(16);SPI.setTX(19);SPI.setSCK(18);// SPI.setCS(cs);SPI.begin();}void loop() {// put your main code here, to run repeatedly:uint8_t whoami = read_register(0x0F);Serial.print("Who am I: ");Serial.println(whoami, HEX);Serial.println("heeey");delay(2000);}

author: moffy
author_rank: Super Contributor
timestamp: March 15, 2024, 12:10:16 pm
content: Just a possibility, that you are getting some fast glitches which are not fully showing on the scope and the scope capacitance is filtering them. It's the edges which could be the issue. Try a 10-20pf capacitor to gnd on the clock and data lines, you might have cross talk and or a bad ground.

author: NiHaoMike
author_rank: Super Contributor
timestamp: March 15, 2024, 12:17:57 pm
content: Check that the SPI is configured to use the correct edges.

author: sophokles
author_rank: Newbie
timestamp: March 15, 2024, 01:03:10 pm
content: You could try adding series resistors of 22 to 100 ohm to MISO/MOSI/SCK lines to reduce ringing, see:https://www.edaboard.com/threads/spi-serial-resistor.345440/

author: pcprogrammer
author_rank: Super Contributor
timestamp: March 15, 2024, 02:58:02 pm
content: Quote from: moffy on March 15, 2024, 12:10:16 pmYes. A probe has capacitance, and it might suppress some spikes and glitches. The signals on the scope do show ringing. But this could also be bad probe adjustment.The problem with the ringing depends on the rate with which the transition occurs and with a push pull output it can be fast even when the clock speed is low. So lowering the clock won't solve the problem.Quote from: sophokles on March 15, 2024, 01:03:10 pmThis probably is a better solution than capacitors to ground.Quote from: NiHaoMike on March 15, 2024, 12:17:57 pmNot an issue when it works as intended with the probes connected and not without them.

author: mrmp17
author_rank: Contributor
timestamp: March 15, 2024, 03:35:32 pm
content: Thanks everybody! Adding 50series termination on driving sides of the wires seems to have helped. The combination of RP2040 drive strength and a few cm of wire must have caused enough ringing to corrupt the data, but went away when scope's input capacitance was added. Ringing in the scope screenshot is due to a long-ish ground lead for the probes I think. With proper probing, edges now look pretty good!