Closed nit1995 closed 4 years ago
@nit1995 Can you post the relevant parts of the code you are using? With just such a generic error message it's hard to tell what went wrong.
I guess you are using the Nordic_nRF5_series/sensirion_hw_i2c_implementation.c
?
Did you verify that the pin numbers match your platform?
/** * Nordic specific configuration. Change the pin numbers if you use other pins * than defined below. */ #define SENSIRION_SDA_PIN 0 #define SENSIRION_SCL_PIN 2
Yes. I am using Nordic_nRF5_series/sensirion_hw_i2c_implementation.c
and I changed the pin numbers to match the nRF52 DK board.
I have included the sensirion_common.h, sensirion_arch_config.h, sensirion_common.h, sensirion_i2c.hand sps30.h.
I have used the following example code:
static void test_sps30_pm_sensor(void)
{
//struct sps30_measurement m; //make it global variable
char serial[SPS_MAX_SERIAL_LEN];
u8 auto_clean_days = 4;
u32 auto_clean;
u16 data_ready;
s16 ret;
nrf_delay_ms(5000);
// Start execution.
NRF_LOG_INFO("PM Sensor Initialization started.");
int x = sps30_probe();
while (x != 0) {
printf("PM Sensor Initialization failed\n");
NRF_LOG_INFO("PM Sensor Initialization failed.");
// sleep(1);
}
printf("PM Sensor Initialization successful\n");
ret = sps30_set_fan_auto_cleaning_interval_days(auto_clean_days);
if (ret)
printf("error %d setting the auto-clean interval\n", ret);
ret = sps30_start_measurement();
if (ret < 0)
printf("error starting measurement\n");
printf("measurements started\n");
// sleep(1);
nrf_delay_ms(1);
//do {
do {
ret = sps30_read_data_ready(&data_ready);
if (ret < 0)
printf("error %d reading data-ready flag\n", ret);
else if (!data_ready)
printf("data not ready, no new measurement available\n");
else
break;
//usleep(100000); /* retry in 100ms */
nrf_delay_ms(100);
} while (1);
ret = sps30_read_measurement(&m);
if (ret < 0) {
printf("error reading measurement\n");
} else {
printf("measured values:\n"
"\t%0.2f pm1.0\n"
"\t%0.2f pm2.5\n"
"\t%0.2f pm4.0\n"
"\t%0.2f pm10.0\n"
"\t%0.2f nc0.5\n"
"\t%0.2f nc1.0\n"
"\t%0.2f nc2.5\n"
"\t%0.2f nc4.5\n"
"\t%0.2f nc10.0\n"
"\t%0.2f typical particle size\n\n",
m.mc_1p0, m.mc_2p5, m.mc_4p0, m.mc_10p0,
m.nc_0p5, m.nc_1p0, m.nc_2p5, m.nc_4p0, m.nc_10p0,
m.typical_particle_size);
}
ret = sps30_stop_measurement();
// sleep(1);
nrf_delay_ms(1);
// } while (1);
return 0;
}
The code keeps getting stuck at NRF_BREAKPOINT_COND.
OK. So since the nrf_drv_twi_init
call seems to fail (From the error message Error 8: Initialization of I2C connection failed!
which gets emitted in sensirion_i2c_init
), I would guess that something with the configuration or the used NRF_DRV_TWI_INSTANCE
is wrong.
Can you compare the default config for the used NRF_DRV_TWI_INSTANCE
with the one set in the init function? For example by just printing the .scl
, .sda
, .frequency
and .interrupt_priority
field of the default config.
Otherwise you may be better of asking in a Nordic / nRF32 support forum about the I2C/TWI interface, since the error happens in the nRF code.
@nit1995 : maybe it is any communication / buffer problem?
You can try my simple sketch - maybe it will help. you can here better look for the problem, maybe. https://smarthome-work.com/blog/?particulate-matter-sensor-sps30-and-arduino
It is working with small buffer too - but then only for the first 5 values.
@nit1995 Could you get it to work? If yes I'll close the issue. If no is there a way we can support you?
The PM Sensor fails to initialise when using with nRF52 DK. I am using Segger Embedded Studio. The code keeps getting routed to NRF_BREAKPINT_COND in app_error_weak.c. This is the error I am getting.
`Error 8: Initialization of I2C connection failed!