1. 程式人生 > >STM32的HAL庫的 I2C和UART使用函式,幾個好用的

STM32的HAL庫的 I2C和UART使用函式,幾個好用的

void I2C_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr,uint16_t NumByteToWrite){
  //HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)DeviceAddr, pBuffer, NumByteToWrite, 1000);//1000ms 1s 100K位元組s
}

void I2C_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead){
  uint8_t Register[3]={RegisterAddr};
  HAL_I2C_Master_Transmit(&hi2c1, (uint16_t)DeviceAddr, Register, 1, 1000);
  HAL_I2C_Master_Receive(&hi2c1, (uint16_t)DeviceAddr, pBuffer, NumByteToRead, 1000);
}
HAL_UART_Transmit(&huart1, testChar, 15, 1000);