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)