I am trying to use an SPS30 with a custom-built RAK3172 board running on RUI3. But I am not able to read SPS30 on the i2c port. I can read the rest of the i2c devices, like DS3231, SCD30, and many more devices except SPS30. I tested the sensor with an ESP32, and it works fine with it. Below is the code which I used for scanning.
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(115200);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
The same thing I am able to read the device in Mbed OS when I scan for i2c devices. (SPS30 address is 0x69)
I am not sure why RAK3172 and other boards can. Hmm. Some things I have in mind.
What is your pull up resistor? Also VDD levels?
Do you have a oscilloscope where we can see the I2C signals? Might be helpful to see the pulses, signal levels, skew, decoded data. (only if possible or you have one)
Might not be really necessary but can you try to introduce little delay between begin and end transmission?
Thanks for your comment. I have done everything with it. With the same RAK3172 board, I am able to make it work with Mbed Studio. The setup also has a DS3231. I think the problem is with RUI3 or the library not supporting RUI3.
If you use a library for SPS30, we cannot guarantee it can be directly compatible to RUI3. However, even if only at I2C device scanning phase, the SPS30 is not detected, we really have to look on the i2c bus.
I tried adding a delay between transmission begin and end transmission. But I was still not able to scan it. However, with the same hardware setup and Mbed OS, I can successfully scan the device.
Does this have anything to do with i2c clock frequency? Should I check that as well?
Btw, one more thing you can try is to lessed the pull-up resistor value. If you are using 10k, probably try 4.7k or 2.1k (lowest). These are just blind fix attempts. The best way really is to see the signal where it is failing via oscilloscope or logic analyzer.