You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<stdio.h>#include"pico/stdlib.h"#include"pio_i2c.h"#definePIN_SDA 20
#definePIN_SCL 21
// data must be at least 2 bytes long.voidprint_temperature(uint8_t*data) {
int16_tdata_i16= ((int16_t)data[0]) << 8 | (data[1] &0xE0);
floattemp= (float)data_i16*0.125;
printf("%0.2fC\n", temp);
}
intmain() {
stdio_init_all();
PIOpio=pio0;
uintsm=0;
uintoffset=pio_add_program(pio, &i2c_program);
i2c_program_init(pio, sm, offset, PIN_SDA, PIN_SCL);
uint8_tdata[2] = {0};
// LM75B's default pointer is to temperature register.pio_i2c_read_blocking(pio, sm, 0x48, data, 2);
print_temperature(data);
// Set pointer register to Temperature register.data[0] =0x0;
pio_i2c_write_blocking(pio, sm, 0x48, data, 1);
// Read again temperature now corruptedpio_i2c_read_blocking(pio, sm, 0x48, data, 2);
print_temperature(data);
printf("Done.\n");
return0;
}
The text was updated successfully, but these errors were encountered:
ithinuel
changed the title
The pio_i2c example's write operation do not work and corrupt every subsequent transaction.
The pio_i2c example's write operation corrupt every subsequent transaction.
Oct 19, 2021
Tested using an NXP LM75B temperature sensor.
Minimal code to reproduce:
The text was updated successfully, but these errors were encountered: