550 lines
14 KiB
C
550 lines
14 KiB
C
/**
|
|
******************************************************************************
|
|
* @file dallas_tools.c
|
|
* @brief Äðàéâåð äëÿ ðàáîòû ñ äàò÷èêàìè òåìïåðàòóðû DS18B20
|
|
* @author MicroTechnics (microtechnics.ru)
|
|
******************************************************************************
|
|
@details
|
|
Ýòîò ôàéë ñîäåðæèò ðåàëèçàöèþ ôóíêöèé äëÿ ðàáîòû ñ äàò÷èêîì DS18B20
|
|
÷åðåç èíòåðôåéñ 1-Wire. Îí ïðåäîñòàâëÿåò ôóíêöèè äëÿ ÷òåíèÿ è çàïèñè
|
|
êîíôèãóðàöèè, âûïîëíåíèÿ èçìåðåíèé è îáðàáîòêè ïîëó÷åííûõ äàííûõ.
|
|
*****************************************************************************/
|
|
|
|
|
|
/* Includes ----------------------------------------------------------------*/
|
|
|
|
#include "dallas_tools.h"
|
|
#include "string.h"
|
|
|
|
|
|
/* Declarations and definitions --------------------------------------------*/
|
|
|
|
/* Functions ---------------------------------------------------------------*/
|
|
/**
|
|
* @brief Ôóíêöèÿ äëÿ íàõîæäåíèÿ íîâîãî äàò÷èêà íà ìåñòî ïîòåðÿííîãî
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_HandleTypeDef *sensor)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
|
|
result = Dallas_IsConnected(sensor);
|
|
|
|
if(sensor->isLost)
|
|
{
|
|
if(DS18B20_Search(&DS, &OW) != HAL_OK)
|
|
return HAL_ERROR;
|
|
|
|
if(sensor->Init.init_func(sensor->onewire, sensor) != HAL_OK)
|
|
return HAL_ERROR;
|
|
|
|
return HAL_OK;
|
|
}
|
|
else
|
|
{
|
|
return HAL_BUSY; // äàò÷èê íå ïîòåðÿí
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Ôóíêöèÿ äëÿ èíèèöàëèçàöèè íîâîãî äàò÷èêà â ñòðóêòóðå
|
|
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_AddNewSensors(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
if(onewire == NULL)
|
|
return HAL_ERROR;
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
|
|
sensor->onewire = onewire;
|
|
|
|
result = sensor->Init.init_func(onewire, sensor);
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @brief Èíèöèàëèçèðóåò ñòðóêòóðó äàò÷èêà ïî ROM
|
|
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
if(onewire == NULL)
|
|
return HAL_ERROR;
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
|
|
uint8_t ROM[8] = {0};
|
|
ROM[0] = (sensor->Init.ROM >> (0*8)) & 0xFF;
|
|
ROM[1] = (sensor->Init.ROM >> (1*8)) & 0xFF;
|
|
ROM[2] = (sensor->Init.ROM >> (2*8)) & 0xFF;
|
|
ROM[3] = (sensor->Init.ROM >> (3*8)) & 0xFF;
|
|
ROM[4] = (sensor->Init.ROM >> (4*8)) & 0xFF;
|
|
ROM[5] = (sensor->Init.ROM >> (5*8)) & 0xFF;
|
|
ROM[6] = (sensor->Init.ROM >> (6*8)) & 0xFF;
|
|
ROM[7] = (sensor->Init.ROM >> (7*8)) & 0xFF;
|
|
|
|
if(DS18B20_IsValidAddress(ROM) != HAL_OK)
|
|
return HAL_ERROR;
|
|
|
|
uint8_t comparebytes = DALLAS_ROM_SIZE;
|
|
int ROM_ind = 0;
|
|
for(int i = 0; i < onewire->RomCnt; i++)
|
|
{
|
|
comparebytes = DALLAS_ROM_SIZE;
|
|
for(int rom_byte = 0; rom_byte < DALLAS_ROM_SIZE; rom_byte++)
|
|
{
|
|
if(DS.DevAddr[i][rom_byte] == ROM[rom_byte])
|
|
comparebytes--;
|
|
}
|
|
if(comparebytes == 0)
|
|
{
|
|
ROM_ind = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
|
if(comparebytes == 0)
|
|
{
|
|
|
|
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[ROM_ind]);
|
|
return result;
|
|
}
|
|
else
|
|
{
|
|
return HAL_ERROR;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @brief Èíèöèàëèçèðóåò ñòðóêòóðó äàò÷èêà ïî ïîëüçîâàòåëüñêèì áàéòàì
|
|
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
if(onewire == NULL)
|
|
return HAL_ERROR;
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
|
|
uint8_t UserByte1 = sensor->Init.UserBytes12 & 0xFF;
|
|
uint8_t UserByte2 = sensor->Init.UserBytes12 >> 8;
|
|
uint8_t UserByte3 = sensor->Init.UserBytes34 & 0xFF;
|
|
uint8_t UserByte4 = sensor->Init.UserBytes34 >> 8;
|
|
uint8_t UserByte12Cmp = 0;
|
|
uint8_t UserByte34Cmp = 0;
|
|
|
|
DALLAS_ScratchpadTypeDef scratchpad;
|
|
for(int i = 0; i < onewire->RomCnt; i++)
|
|
{
|
|
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
|
result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
|
|
if (result != HAL_OK)
|
|
return result;
|
|
|
|
/* Ñðàâíåíèå UserByte1 è UserByte2, åñëè îíè íå ðàâíû íóëþ */
|
|
if(sensor->Init.UserBytes12 != NULL)
|
|
{
|
|
if( (scratchpad.tHighRegister == UserByte1) &&
|
|
(scratchpad.tLowRegister == UserByte2))
|
|
{
|
|
UserByte12Cmp = 1;
|
|
}
|
|
}/* Åñëè ñðàâíåíèå UserByte1 è UserByte2 íå âûáðàíî, òî ñ÷èòàåì ÷òî îíè ñîâïàäàþò */
|
|
else
|
|
{
|
|
UserByte12Cmp = 1;
|
|
}
|
|
/* Ñðàâíåíèå UserByte3 è UserByte4, åñëè îíè íå ðàâíû íóëþ */
|
|
if(sensor->Init.UserBytes34 != NULL)
|
|
{
|
|
if( (scratchpad.UserByte3 == UserByte3) &&
|
|
(scratchpad.UserByte4 == UserByte4))
|
|
{
|
|
UserByte34Cmp = 1;
|
|
}
|
|
}/* Åñëè ñðàâíåíèå UserByte3 è UserByte4 íå âûáðàíî, òî ñ÷èòàåì ÷òî îíè îäèíàêîâûå */
|
|
else
|
|
{
|
|
UserByte34Cmp = 1;
|
|
}
|
|
/* Åñëè íàøëè íóæíûé äàò÷èê - çàâåðøàåì ïîèñê */
|
|
if(UserByte12Cmp && UserByte34Cmp)
|
|
{
|
|
// sensor->isInitialized = 1;
|
|
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
|
|
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[i]);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
sensor->sensROM = 0;
|
|
memset(&sensor->scratchpad, 0, sizeof(DALLAS_ScratchpadTypeDef));
|
|
/* Âîçâðàùàåì îøèáêó åñëè íå íàøëè */
|
|
return HAL_ERROR;
|
|
}
|
|
|
|
/**
|
|
* @brief Èíèöèàëèçèðóåò ñòðóêòóðó äàò÷èêà ïî ïîðÿäêîâîìó íîìåðó
|
|
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @retval HAL Status
|
|
* @details Ïîðÿäêîâûé íîìåð äàò÷èêà â ñïèñêå íàéäåííûõ.
|
|
* Ò.å. êàêèì ïî ñ÷åòó ýòîò äàò÷èê áûë íàéäåí
|
|
*/
|
|
HAL_StatusTypeDef Dallas_SensorInitByInd(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
if(onewire == NULL)
|
|
return HAL_ERROR;
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
|
|
// sensor->onewire = onewire;
|
|
// sensor->sensROM = &DS.DevAddr[sensor->Init.SensInd];
|
|
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByInd;
|
|
|
|
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[sensor->Init.SensInd]);
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* @brief Èíèöèàëèçèðóåò äàò÷èê äëÿ ðàáîòû
|
|
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @param ROM ROM äàò÷èêà, êîòîðûé íàäî èíèöèàëèçèðîâàòü
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint8_t (*ROM)[DALLAS_ROM_SIZE])
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
if(onewire == 0)
|
|
return HAL_ERROR;
|
|
|
|
sensor->onewire = onewire;
|
|
sensor->sensROM = 0;
|
|
sensor->sensROM = *(uint64_t *)(ROM);
|
|
// for(int i = 0; i < DALLAS_ROM_SIZE; i++)
|
|
// sensor->sensROM |= ((uint64_t)(*ROM)[i] << (56 - 8*i));
|
|
|
|
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
|
result = DS18B20_ReadScratchpad(sensor->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->scratchpad);
|
|
if (result == HAL_OK)
|
|
{
|
|
/* Óñòàíîâêà ðàçðåøåíèÿ */
|
|
result = DS18B20_SetResolution(onewire, (uint8_t *)ROM, sensor->Init.Resolution);
|
|
if (result == HAL_OK)
|
|
{
|
|
sensor->isInitialized = 1;
|
|
return HAL_OK;
|
|
}
|
|
else
|
|
{
|
|
sensor->isInitialized = 0;
|
|
return result;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sensor->isInitialized = 0;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Äåèíèöèàëèçèðóåò ñòðóêòóðó äàò÷èêà
|
|
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @param sens_ind Ïîðÿäêîâûé íîìåð äàò÷èêà â ñòðóêòóðå
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_HandleTypeDef *sensor)
|
|
{
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
|
|
DALLAS_InitStructTypeDef initbuff = sensor->Init;
|
|
|
|
memset(sensor, 0, sizeof(DALLAS_HandleTypeDef));
|
|
|
|
sensor->Init = initbuff;
|
|
|
|
return HAL_OK;
|
|
}
|
|
|
|
/**
|
|
* @brief Çàïóñêàåò èçìåðåíèå òåìïåðàòóðû íà âñåõ äàò÷èêàõ
|
|
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
|
* @param waitCondition Óñëîâèå îæèäàíèÿ çàâåðøåíèÿ ïðåîáðàçîâàíèÿ
|
|
* @param dallas_delay_ms Âðåìÿ îæèäàíèÿ îêîí÷àíèÿ êîíâåðñèè
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_StartConvertTAll(OneWire_t *onewire, DALLAS_WaitConvertionTypeDef waitCondition, uint8_t dallas_delay_ms)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
uint8_t rxDummyData;
|
|
|
|
if(onewire == NULL)
|
|
return HAL_ERROR;
|
|
|
|
// Îòïðàâêà êîìàíäû íà÷àëà ïðåîáðàçîâàíèÿ òåìïåðàòóðû
|
|
result = DS18B20_StartConvTAll(onewire);
|
|
if(result != HAL_OK)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
// Îæèäàíèå çàâåðøåíèÿ ïðåîáðàçîâàíèÿ, ïóòåì ïðîâåðêè øèíû
|
|
if (waitCondition == DALLAS_WAIT_BUS)
|
|
{
|
|
result = DS18B20_WaitForEndConvertion(onewire);
|
|
return result;
|
|
}
|
|
|
|
// Îæèäàíèå çàâåðøåíèÿ ïðåîáðàçîâàíèÿ, ïóòåì çàäåðæêè
|
|
if (waitCondition == DALLAS_WAIT_DELAY)
|
|
{
|
|
uint32_t delayValueMs = 0;
|
|
|
|
switch (dallas_delay_ms)
|
|
{
|
|
case DALLAS_CONFIG_9_BITS:
|
|
delayValueMs = DALLAS_DELAY_MS_9_BITS;
|
|
break;
|
|
|
|
case DALLAS_CONFIG_10_BITS:
|
|
delayValueMs = DALLAS_DELAY_MS_10_BITS;
|
|
break;
|
|
|
|
case DALLAS_CONFIG_11_BITS:
|
|
delayValueMs = DALLAS_DELAY_MS_11_BITS;
|
|
break;
|
|
|
|
case DALLAS_CONFIG_12_BITS:
|
|
delayValueMs = DALLAS_DELAY_MS_12_BITS;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
HAL_Delay(delayValueMs);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* @brief Èçìåðÿåò òåìïåðàòóðó íà äàò÷èêå
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @param waitCondition Óñëîâèå îæèäàíèÿ çàâåðøåíèÿ ïðåîáðàçîâàíèÿ
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_ConvertT(DALLAS_HandleTypeDef *sensor, DALLAS_WaitConvertionTypeDef waitCondition)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
uint8_t rxDummyData;
|
|
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
if(sensor->isInitialized == 0)
|
|
return HAL_ERROR;
|
|
|
|
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
|
result = Dallas_IsConnected(sensor);
|
|
if (result != HAL_OK)
|
|
return result;
|
|
|
|
// Îòïðàâêà êîìàíäû íà÷àëà ïðåîáðàçîâàíèÿ òåìïåðàòóðû
|
|
result = DS18B20_StartConvT(sensor->onewire, (uint8_t *)&sensor->sensROM);
|
|
if(result != HAL_OK)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
// Îæèäàíèå çàâåðøåíèÿ ïðåîáðàçîâàíèÿ, ïóòåì ïðîâåðêè øèíû
|
|
if (waitCondition == DALLAS_WAIT_BUS)
|
|
{
|
|
result = DS18B20_WaitForEndConvertion(sensor->onewire);
|
|
if(result == HAL_TIMEOUT)
|
|
{
|
|
sensor->f.timeout_convertion_cnt++;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Îæèäàíèå çàâåðøåíèÿ ïðåîáðàçîâàíèÿ, ïóòåì çàäåðæêè
|
|
if (waitCondition == DALLAS_WAIT_DELAY)
|
|
{
|
|
uint32_t delayValueMs = 0;
|
|
|
|
switch (sensor->scratchpad.ConfigRegister)
|
|
{
|
|
case DALLAS_CONFIG_9_BITS:
|
|
delayValueMs = DALLAS_DELAY_MS_9_BITS;
|
|
break;
|
|
|
|
case DALLAS_CONFIG_10_BITS:
|
|
delayValueMs = DALLAS_DELAY_MS_10_BITS;
|
|
break;
|
|
|
|
case DALLAS_CONFIG_11_BITS:
|
|
delayValueMs = DALLAS_DELAY_MS_11_BITS;
|
|
break;
|
|
|
|
case DALLAS_CONFIG_12_BITS:
|
|
delayValueMs = DALLAS_DELAY_MS_12_BITS;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
HAL_Delay(delayValueMs);
|
|
}
|
|
|
|
/* Íå ñ÷èòûâàåì òåìïåðàòóðó, åñëè íå âûáðàíî îæèäàíèå îêîí÷àíèÿ ïðåîáðàçîâàíèÿ */
|
|
if(waitCondition != DALLAS_WAIT_NONE)
|
|
{
|
|
result = Dallas_ReadTemperature(sensor);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief ×èòàåò èçìåðåííóþ äàò÷èêîì òåìïåðàòóðó
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_HandleTypeDef *sensor)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
if(sensor->isInitialized == 0)
|
|
return HAL_ERROR;
|
|
|
|
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
|
result = Dallas_IsConnected(sensor);
|
|
if (result != HAL_OK)
|
|
return result;
|
|
|
|
|
|
result = DS18B20_CalcTemperature(sensor->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->scratchpad, &sensor->temperature);
|
|
|
|
if (result != HAL_OK)
|
|
{
|
|
sensor->f.read_temperature_err_cnt++;
|
|
return result;
|
|
}
|
|
|
|
return HAL_OK;
|
|
}
|
|
|
|
/**
|
|
* @brief Ïðîâåðÿåò ïîäêëþ÷åí ëè äàò÷èê (÷òåíèå scratchpad)
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @retval HAL Status
|
|
*/
|
|
HAL_StatusTypeDef Dallas_IsConnected(DALLAS_HandleTypeDef *sensor)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
if(sensor->isInitialized == 0)
|
|
return HAL_ERROR;
|
|
|
|
result = DS18B20_ReadScratchpad(sensor->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->scratchpad);
|
|
|
|
if (result == HAL_OK)
|
|
{
|
|
sensor->isConnected = 1;
|
|
sensor->isLost = 0;
|
|
return HAL_OK;
|
|
}
|
|
else
|
|
{
|
|
|
|
if(sensor->isConnected == 1)
|
|
{
|
|
sensor->f.disconnect_cnt++;
|
|
sensor->isLost = 1;
|
|
}
|
|
sensor->isConnected = 0;
|
|
|
|
// Dallas_ReplaceLostedSensor(sensor);
|
|
return HAL_BUSY; // èñïîëüçóþ busy, ÷òîáû îòëè÷àòü ñèòóàöèþ îò HAL_ERROR
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Çàïèñûâàåò ïîëüçîâàòåëüñêèå áàéòû
|
|
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
|
* @param UserBytes12 Ïîëüçîâàòåëüñêèå áàéòû 1 è 2
|
|
* @param UserBytes34 Ïîëüçîâàòåëüñêèå áàéòû 3 è 4
|
|
* @param UserBytesMask Ìàñêà, êàêèå áàéòû çàïèñûâàòü, à êàêèå íåò
|
|
* @retval HAL Status
|
|
* @details ñòàðøèé áàéò - UserByte4/UserByte2, ìëàäøèé - UserByte3/UserByte1.
|
|
*/
|
|
HAL_StatusTypeDef Dallas_WriteUserBytes(DALLAS_HandleTypeDef *sensor, uint16_t UserBytes12, uint16_t UserBytes34, uint8_t UserBytesMask)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
if(sensor->isInitialized == 0)
|
|
return HAL_ERROR;
|
|
|
|
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
|
result = Dallas_IsConnected(sensor);
|
|
if (result != HAL_OK)
|
|
return result;
|
|
|
|
result = DS18B20_WriteUserBytes(sensor->onewire, (uint8_t *)&sensor->sensROM, UserBytes12, UserBytes34, UserBytesMask);
|
|
if (result != HAL_OK)
|
|
{
|
|
sensor->f.other_err_cnt++;
|
|
return result;
|
|
}
|
|
result = DS18B20_ReadScratchpad(sensor->onewire, (uint8_t *)&sensor->sensROM, (uint8_t *)&sensor->scratchpad);
|
|
if (result != HAL_OK)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|