
利用HAL库函数,访问从设备16位寄存器机数据,函数如下: int Dev_I2C_W16(uint16_t reg_addr,uint16_t data) { uint8_t tx_buffer[4]; tx_buffer[0]=reg_addr>>8;//reg_MSB tx_buffer[1]=reg_addr; //reg_LSB tx_buffer[2]=data; //data_LSB tx_buffer[3]=data>>8; //data_MSB HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)I2C_ADDRESS, tx_buffer, 4, 100); return 0; } 求大神指导一下,这种写法是否正确?谢谢! |