stm32f0_clock: convert tabs to spaces

This commit is contained in:
wangyz1997 2024-12-06 15:52:54 +08:00
parent 7e37a19f22
commit cf7518d5eb
5 changed files with 37 additions and 37 deletions

View File

@ -12,7 +12,7 @@ static void bsp_ds18b20_delay_us(uint16_t delay_us) //实际延时时间会比de
static void bsp_ds18b20_reset_bus(void)
{
HAL_GPIO_WritePin(ONEWIRE_GPIO_Port, ONEWIRE_Pin, GPIO_PIN_RESET); //拉低DQ
bsp_ds18b20_delay_us(500); //拉低500us 复位总线
bsp_ds18b20_delay_us(500); //拉低500us 复位总线
HAL_GPIO_WritePin(ONEWIRE_GPIO_Port, ONEWIRE_Pin, GPIO_PIN_SET);
}
@ -93,25 +93,25 @@ HAL_StatusTypeDef bsp_ds18b20_start_conv(void) //开始温度转换
HAL_StatusTypeDef bsp_ds18b20_get_temp(float *temp_out)
{
bsp_ds18b20_reset_bus();
bsp_ds18b20_reset_bus();
HAL_StatusTypeDef res = bsp_ds18b20_check_present();
if (res != HAL_OK) {
return res;
}
bsp_ds18b20_write_byte(0xCC); //跳过ROM
bsp_ds18b20_write_byte(0xBE); //读Scratchpad
uint8_t temp_lsb = bsp_ds18b20_read_byte(); //Scratchpad第0字节 温度LSB
uint8_t temp_msb = bsp_ds18b20_read_byte(); //Scratchpad第1字节 温度MSB
bsp_ds18b20_write_byte(0xCC); //跳过ROM
bsp_ds18b20_write_byte(0xBE); //读Scratchpad
uint8_t temp_lsb = bsp_ds18b20_read_byte(); //Scratchpad第0字节 温度LSB
uint8_t temp_msb = bsp_ds18b20_read_byte(); //Scratchpad第1字节 温度MSB
if(temp_msb & 0x80) { //温度为负
if(temp_msb & 0x80) { //温度为负
int16_t temp = (~temp_msb) << 8 | (~temp_lsb); //转换为正数
*temp_out = -0.0625f * temp; //输出负数
} else { //温度为正
} else { //温度为正
int16_t temp = temp_msb << 8 | temp_lsb;
*temp_out = 0.0625f * temp; //12位转换精度 每LSB等于0.0625度
}
}
return HAL_OK;
}