Hello,
found nothing in the forum which addresses my issues, so I'll ask the community.
I try to setup a RPi Pico to work with an I²C sensor.
setting up the I²C:try to write two bytes to the sensor
... but reading failed.
Evaluating iLen, I found a value of -2, meaning TIMEOUT. So I measured the signals direct on the I²C-lines, to get the reason.
Here I found, that only 1 byte is transferred or received.
Playing around to get a response, I found, that using i2c_write_blocking / i2c_read_blockingm would fix the issue.
This behaviour is reproducable!
So this code would fix it...:
But in my expectations according the nomenclature this will block the controller forever, if anything go wrong on the bus. This was the reason for me to use the *_until commands for having an always correct error return.
Am I wrong or may this be a bug in the SDK?
found nothing in the forum which addresses my issues, so I'll ask the community.
I try to setup a RPi Pico to work with an I²C sensor.
setting up the I²C:
Code:
// I2C Initialisation @ 400Khz. printf ("Opened I2C with %lu Hz Baudrate\n", i2c_init(I2C_PORT, 400*1000)); gpio_set_function(I2C_SDA, GPIO_FUNC_I2C); gpio_set_function(I2C_SCL, GPIO_FUNC_I2C); gpio_pull_up(I2C_SDA); gpio_pull_up(I2C_SCL);Code:
aui8Byte[0] = 0x24; // one shot trigger aui8Byte[1] = 0x00; // lowest power dissipation iLen = i2c_write_blocking_until(I2C_PORT, SENSORBASEADRESS, aui8Byte, 2u, false, 10000u); iLen = i2c_read_blocking_until(I2C_PORT, SENSORBASEADRESS, aui8Byte, 6u, false, 10000u);... but reading failed.
Evaluating iLen, I found a value of -2, meaning TIMEOUT. So I measured the signals direct on the I²C-lines, to get the reason.
Here I found, that only 1 byte is transferred or received.
Playing around to get a response, I found, that using i2c_write_blocking / i2c_read_blockingm would fix the issue.
This behaviour is reproducable!
So this code would fix it...:
Code:
aui8Byte[0] = 0x24; // one shot trigger aui8Byte[1] = 0x00; // lowest power dissipation iLen = i2c_write_blocking(I2C_PORT, SENSORBASEADRESS, aui8Byte, 2u, false, 10000u); iLen = i2c_read_blocking(I2C_PORT, SENSORBASEADRESS, aui8Byte, 6u, false, 10000u);But in my expectations according the nomenclature this will block the controller forever, if anything go wrong on the bus. This was the reason for me to use the *_until commands for having an always correct error return.
Am I wrong or may this be a bug in the SDK?
Statistics: Posted by Eselchen — Sat Aug 16, 2025 2:40 pm