#include "hardware/i2c.h"
#include "pico/binary_info.h"
#define I2C_SDA 16
#define I2C_SCL 17
void setup() {
// put your setup code here, to run once:
Serial.begin( 115200 );
i2c_init( i2c_default, 100*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);
bi_decl(bi_2pins_with_func(I2C_SDA, I2C_SCL,GPIO_FUNC_I2C));
uint8_t registerid = 0x00;
uint16_t value = 0x4527;
uint8_t data[3];
data[0] = 0x00;
data[1] = value >> 8;
data[2] = value & 0x00ff;
i2c_write_blocking(i2c_default, 0x40, data, sizeof(data), true );
for( ;; )
{
value = 0;
i2c_write_blocking(i2c_default, 0x40, & registerid, sizeof(registerid), true );
i2c_read_blocking (i2c_default, 0x40, (uint8_t *) & value, sizeof(value), false );
value = value >> 8 | value << 8;
Serial.printf( "%X\n", value );
}
}
改写 0x00 寄存器的初始值,并获取打印这个寄存器的值。