找到一个多字节写的code,如下,逻辑上没有错误,但是sht没有子地址吧,函数里有个uint8_t reg_addr,如何替换
I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
{
/* Initialize state machine */
MasterMode = TX_REG_ADDRESS_MODE;
TransmitRegAddr = reg_addr;
//Copy register data to TransmitBuffer
CopyArray(reg_data, TransmitBuffer, count);
TXByteCtr = count;
RXByteCtr = 0;
ReceiveIndex = 0;
TransmitIndex = 0;
/* Initialize slave address and interrupts */
UCB0I2CSA = dev_addr;
IFG2 &= ~(UCB0TXIFG + UCB0RXIFG); // Clear any pending interrupts
IE2 &= ~UCB0RXIE; // Disable RX interrupt
IE2 |= UCB0TXIE; // Enable TX interrupt
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
return MasterMode;
}
下面是stm32的code,HAL_I2C_Master_Transmit(&hi2c1, iic_addr, cmd, 2, 100);函数的功能等同于上面的函数
static void start_measure(void) { const uint8_t iic_addr = 0x44 << 1; const uint16_t cmd_meas_freq = 0x2737; uint8_t cmd[2]; cmd[0] = cmd_meas_freq >> 8; cmd[1] = cmd_meas_freq; HAL_I2C_Master_Transmit(&hi2c1, iic_addr, cmd, 2, 100); }
|