From e4b2830fcc568c4602bacd3880e51c7b26e9d159 Mon Sep 17 00:00:00 2001 From: Razvalyaev Date: Mon, 3 Mar 2025 13:45:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BF=D1=83=D1=81=D1=82=D0=BE=D0=B9=20=D1=83=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=20=D0=B2=20=D0=B4=D1=80?= =?UTF-8?q?=D0=B0=D0=B9=D0=B2=D0=B5=D1=80=D0=B5=20ds18b20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Dallas/ds18b20_driver.c | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Core/Dallas/ds18b20_driver.c b/Core/Dallas/ds18b20_driver.c index b6a1778..a87b63d 100644 --- a/Core/Dallas/ds18b20_driver.c +++ b/Core/Dallas/ds18b20_driver.c @@ -17,6 +17,9 @@ OneWire_t OW; */ HAL_StatusTypeDef DS18B20_IsValidAddress(uint8_t *ROM) { + if(ROM == NULL) + return HAL_ERROR; + uint8_t check_family = (*ROM == DS18B20_FAMILY_CODE); /* Calculate CRC */ uint8_t crc = OneWire_CRC8(ROM, 7); @@ -34,6 +37,9 @@ HAL_StatusTypeDef DS18B20_IsValidAddress(uint8_t *ROM) */ HAL_StatusTypeDef DS18B20_IsValid(uint8_t *ROM) { + if(ROM == NULL) + return HAL_ERROR; + if(*ROM == DS18B20_FAMILY_CODE) return HAL_OK; else @@ -49,6 +55,11 @@ HAL_StatusTypeDef DS18B20_IsValid(uint8_t *ROM) uint8_t DS18B20_GetResolution(OneWire_t* OW, uint8_t *ROM) { uint8_t conf; + if(OW == NULL) + return HAL_ERROR; + if(ROM == NULL) + return HAL_ERROR; + /* Check valid ROM */ if (DS18B20_IsValid(ROM) != HAL_OK) return 0; @@ -85,6 +96,11 @@ uint8_t DS18B20_GetResolution(OneWire_t* OW, uint8_t *ROM) { HAL_StatusTypeDef DS18B20_SetResolution(OneWire_t* OW, uint8_t *ROM, DS18B20_Res_t Resolution) { + if(OW == NULL) + return HAL_ERROR; + if(ROM == NULL) + return HAL_ERROR; + uint8_t th, tl, conf; /* Check valid ROM */ @@ -146,6 +162,11 @@ HAL_StatusTypeDef DS18B20_SetResolution(OneWire_t* OW, uint8_t *ROM, */ HAL_StatusTypeDef DS18B20_StartConvT(OneWire_t* OW, uint8_t *ROM) { + if(OW == NULL) + return HAL_ERROR; + if(ROM == NULL) + return HAL_ERROR; + /* Check if device is DS18B20 */ if(DS18B20_IsValid(ROM) != HAL_OK) return HAL_ERROR; @@ -167,6 +188,9 @@ HAL_StatusTypeDef DS18B20_StartConvT(OneWire_t* OW, uint8_t *ROM) */ HAL_StatusTypeDef DS18B20_StartConvTAll(OneWire_t* OW) { + if(OW == NULL) + return HAL_ERROR; + /* Reset pulse */ OneWire_Reset(OW); @@ -189,6 +213,15 @@ HAL_StatusTypeDef DS18B20_StartConvTAll(OneWire_t* OW) */ HAL_StatusTypeDef DS18B20_CalcTemperature(OneWire_t* OW, uint8_t *ROM, uint8_t *Scratchpad, float *Destination) { + if(OW == NULL) + return HAL_ERROR; + if(ROM == NULL) + return HAL_ERROR; + if(Scratchpad == NULL) + return HAL_ERROR; + if(Destination == NULL) + return HAL_ERROR; + uint16_t temperature; uint8_t resolution; int8_t digit, minus = 0; @@ -265,6 +298,10 @@ HAL_StatusTypeDef DS18B20_CalcTemperature(OneWire_t* OW, uint8_t *ROM, uint8_t * */ HAL_StatusTypeDef DS18B20_ReadScratchpad(OneWire_t* OW, uint8_t *ROM, uint8_t *Scratchpad) { + if(OW == NULL) + return HAL_ERROR; + if(ROM == NULL) + return HAL_ERROR; if(Scratchpad == NULL) return HAL_ERROR; @@ -301,6 +338,8 @@ HAL_StatusTypeDef DS18B20_ReadScratchpad(OneWire_t* OW, uint8_t *ROM, uint8_t *S */ HAL_StatusTypeDef DS18B20_WaitForEndConvertion(OneWire_t* OW) { + if(OW == NULL) + return HAL_ERROR; uint32_t tickstart = HAL_GetTick(); /* Wait until line is released, then coversion is completed */ @@ -326,6 +365,11 @@ HAL_StatusTypeDef DS18B20_WaitForEndConvertion(OneWire_t* OW) HAL_StatusTypeDef DS18B20_SetTempAlarm(OneWire_t* OW, uint8_t *ROM, int8_t Low, int8_t High) { + if(OW == NULL) + return HAL_ERROR; + if(ROM == NULL) + return HAL_ERROR; + uint8_t tl, th, conf; /* Check if device is DS18B20 */ @@ -394,6 +438,11 @@ HAL_StatusTypeDef DS18B20_SetTempAlarm(OneWire_t* OW, uint8_t *ROM, int8_t Low, HAL_StatusTypeDef DS18B20_WriteUserBytes(OneWire_t* OW, uint8_t *ROM, int16_t UserBytes12, int16_t UserBytes34, uint8_t UserBytesMask) { + if(OW == NULL) + return HAL_ERROR; + if(ROM == NULL) + return HAL_ERROR; + uint8_t ub1, ub2, conf, ub3, ub4; uint8_t UserByte1 = UserBytes12 & 0xFF; uint8_t UserByte2 = UserBytes12 >> 8; @@ -512,6 +561,10 @@ HAL_StatusTypeDef DS18B20_WriteUserBytes(OneWire_t* OW, uint8_t *ROM, int16_t Us */ HAL_StatusTypeDef DS18B20_Search(DS18B20_Drv_t *DS, OneWire_t *OW) { + if(OW == NULL) + return HAL_ERROR; + + OW->RomCnt = 0; /* Search all OneWire devices ROM */ while(1)