0

3 Weeks & No Answers...

I am confused... I'm using the i2c_write_blocking function, but getting a strange result:

If I do this - everything works as it should; i.e. I can read the values back from CONFIG_REG, and they match with the values I write below.

#define ADDR _u(0x40)
#define CONFIG_REG _u(0x00)
i2c_init(i2c_default, 100000);
uint8_t condata[3];
condata[0] = CONFIG_REG; 
condata[1] = 97
condata[2] = 37
i2c_write_blocking (i2c_default, ADDR, condata, 3, false);

But if I do this - things do not work as they should; the values I read back do not match with the values I write below.

#define ADDR _u(0x40)
#define CONFIG_REG _u(0x00)
i2c_init(i2c_default, 100000);
uint8_t reg = CONFIG_REG;  
uint8_t condt[2];
condt[0] = 97;
condt[1] = 37;
i2c_write_blocking (i2c_default, ADDR, &reg, 1, true);
i2c_write_blocking (i2c_default, ADDR, condt, 2, false);

And here's how I read the register:

#define ADDR _u(0x40)
#define CONFIG_REG _u(0x00)
i2c_init(i2c_default, 100000);
uint8_t reg = CONFIG_REG;  
uint8_t rcvdata[2];
i2c_write_blocking (i2c_default, ADDR, &reg, 1, true);
i2c_read_blocking (i2c_default, ADDR, rcvdata, 2, false);

I've checked the return values from the two i2c_write_blocking calls, and I get a 1 from the first, and a 2 from the second (i.e. what I should see for the commands above). I'm using a recently-installed SDK for the Pico, and running that on an RPi5.

Can someone explain what is happening?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.