Author Topic: RPi Pico / LSM6DS3TR-C IMU over SPI works only if scope probe is connected!?  (Read 416 times)

0 Members and 1 Guest are viewing this topic.

Offline mrmp17Topic starter

  • Contributor
  • Posts: 38
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  :palm: . 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: [Select]
#include <Arduino.h>
#include <SPI.h>


#define cs 17



uint8_t read_register(uint8_t addr) {
    addr |= 0x80;
    uint8_t out[2] = {addr, 0xFF};
    uint8_t in[2];
   
    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[1];
}

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);
}
« Last Edit: March 15, 2024, 11:59:11 am by mrmp17 »
 

Online moffy

  • Super Contributor
  • ***
  • Posts: 1740
  • Country: au
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.
 

Online NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9019
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Check that the SPI is configured to use the correct edges.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline sophokles

  • Newbie
  • Posts: 6
  • Country: at
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/
 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 3710
  • Country: nl
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.

Yes. 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.

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/

This probably is a better solution than capacitors to ground.

Check that the SPI is configured to use the correct edges.

Not an issue when it works as intended with the probes connected and not without them.

Offline mrmp17Topic starter

  • Contributor
  • Posts: 38
Thanks everybody! Adding 50 \$\Omega\$ series 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!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf