cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting two sensors to the same SPI bus - possible contention

ELask.1
Associate II

Hi,

In our system there's an LSM6DSL accelerometer and LPS22HH barometer connected to the same SPI bus.

When nCS of the accelerometer is asserted (0), the nCS of the barometer is de-asserted (1) and vice versa.

HOWEVER, as nCS=1 (for both sensors) also means that the components works in I2C mode, the following condition occurs (as an example):

  • nCS_Acc = 0, nCS_Baro = 1 : an attempt to communicate with the accelerometer
  • MCU (STM32F412) communicates over SPI - it drives MOSI & SCLK with the relevant acceleromter command
  • Concurrently to the accelerometer, the barometer which is now in I2C mode, receives the MOSI & SCLK signals on its SDA & SCL lines
  • The accelerometer responds as expected on SDO towards the MCU MISO
  • Now, if the barometer interpret the SPI communication to its peer as a valid I2C address byte it ACK on the SDA line, (which is shared with MOSI) and make a bus contention and mess up the communication for both sensors....

My questions are:

  • Do I understand correctly or did I oversee something?
  • How can we avoid a such potential contention/communcation mess up?

Thanks for any advice

1 ACCEPTED SOLUTION

Accepted Solutions
Eleon BORLINI
ST Employee

Hi @Community member​ ,

you are in theory right, there could be some undesired cross talk between the sensors. But it is a remote possibility.

Namely, please note that:

  • The I2C and the SPI are different protocols, often running at different clock speeds, and the first one needs a precise salve address and acknowledges to be effective (i.e. to trigger the digital communication block in the sensors' ASIC).
  • You can however prevent a "false-positive" I2C running setting the device as follows:
    • For the LSM6DSL IMU, you can write the I2C_disable bit of CTRL4_C (13h) register (datasheet p.63);
    • For the LPS22HH pressure sensor, you can write the I2C_DISABLE bit of IF_CTRL (0Eh) register (datasheet p.42).

Please let me know if everything is working.

-Eleon

View solution in original post

2 REPLIES 2
Eleon BORLINI
ST Employee

Hi @Community member​ ,

you are in theory right, there could be some undesired cross talk between the sensors. But it is a remote possibility.

Namely, please note that:

  • The I2C and the SPI are different protocols, often running at different clock speeds, and the first one needs a precise salve address and acknowledges to be effective (i.e. to trigger the digital communication block in the sensors' ASIC).
  • You can however prevent a "false-positive" I2C running setting the device as follows:
    • For the LSM6DSL IMU, you can write the I2C_disable bit of CTRL4_C (13h) register (datasheet p.63);
    • For the LPS22HH pressure sensor, you can write the I2C_DISABLE bit of IF_CTRL (0Eh) register (datasheet p.42).

Please let me know if everything is working.

-Eleon

ELask.1
Associate II

Thanks!

This was very helpful.