Добавлен файлы ow_port для реализации задержек и переключения пинов для конкретного МК
Реализована универсанльная функция дли переинициализации порта
This commit is contained in:
@@ -49,56 +49,139 @@ void Dallas_ReadAll(void)
|
||||
|
||||
void Dallas_FirstInit(void)
|
||||
{
|
||||
uint8_t mask = DALLAS_USER_BYTE_ALL;
|
||||
OW.DataPin = DS_Pin;
|
||||
OW.DataPort = DS_GPIO_Port;
|
||||
DS.Resolution = DS18B20_RESOLUTION_9BITS;
|
||||
|
||||
OneWire_Init(&OW);
|
||||
DS18B20_Search(&DS, &OW);
|
||||
Dallas_SensorInitByInd(&OW, &AllSens.outdoor, 0);
|
||||
Dallas_WriteUserBytes(&AllSens.outdoor, 1, NULL, mask);
|
||||
Dallas_SensorInitByInd(&OW, &AllSens.indoor, 1);
|
||||
Dallas_WriteUserBytes(&AllSens.indoor, 2, NULL, mask);
|
||||
Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 2);
|
||||
Dallas_WriteUserBytes(&AllSens.bathroom, 3, NULL, mask);
|
||||
Dallas_SensorInitByInd(&OW, &AllSens.kitchen, 3);
|
||||
Dallas_WriteUserBytes(&AllSens.kitchen, 4, NULL, mask);
|
||||
Dallas_SensorInitByInd(&OW, &AllSens.big_room, 4);
|
||||
Dallas_WriteUserBytes(&AllSens.big_room, 5, NULL, mask);
|
||||
Dallas_SensorInitByInd(&OW, &AllSens.small_room, 5);
|
||||
Dallas_WriteUserBytes(&AllSens.small_room, 6, NULL, mask);
|
||||
Dallas_SensorInitByInd(&OW, &AllSens.living_room, 6);
|
||||
Dallas_WriteUserBytes(&AllSens.living_room, 7, NULL, mask);
|
||||
Dallas_SensorInitByInd(&OW, &AllSens.basement, 7);
|
||||
Dallas_WriteUserBytes(&AllSens.basement, 8, NULL, mask);
|
||||
|
||||
Dallas_SensorInitByROM(&OW, &AllSens.outdoor, 0x28C60C61060000DC);
|
||||
Dallas_SensorInitByROM(&OW, &AllSens.indoor, 0x283E4861060000F9);
|
||||
Dallas_SensorInitByROM(&OW, &AllSens.bathroom, 0x28876D60060000CD);
|
||||
|
||||
|
||||
uint8_t mask = DALLAS_USER_BYTE_ALL;
|
||||
// Dallas_SensorInitByUserBytes(&OW, &AllSens.outdoor, 1, NULL);
|
||||
// Dallas_SensorInitByUserBytes(&OW, &AllSens.indoor, 2, NULL);
|
||||
// Dallas_SensorInitByUserBytes(&OW, &AllSens.bathroom, 3, NULL);
|
||||
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.outdoor, 0);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.indoor, 1);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 2);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.kitchen, 3);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.big_room, 4);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.small_room, 5);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.living_room, 6);
|
||||
// Dallas_SensorInitByInd(&OW, &AllSens.basement, 7);
|
||||
//
|
||||
//
|
||||
// Dallas_WriteUserBytes(&AllSens.outdoor, 1, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.indoor, 2, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.bathroom, 3, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.kitchen, 4, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.big_room, 5, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.small_room, 6, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.living_room, 7, NULL, mask);
|
||||
// Dallas_WriteUserBytes(&AllSens.basement, 8, NULL, mask);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Èíèöèàëèçèðóåò ñòðóêòóðó äàò÷èêà ïî èíäåêó
|
||||
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
||||
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
||||
* @param ROM Óêàçàòåëü íà ROM äëÿ îïðåäåëåíèÿ íóæíîãî äàò÷èêà
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint64_t intROM)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
sensor->isInitialized = 0;
|
||||
if(onewire == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
sensor->onewire = onewire;
|
||||
|
||||
uint8_t ROM[8] = {0};
|
||||
ROM[0] = (intROM >> (7*8)) & 0xFF;
|
||||
ROM[1] = (intROM >> (6*8)) & 0xFF;
|
||||
ROM[2] = (intROM >> (5*8)) & 0xFF;
|
||||
ROM[3] = (intROM >> (4*8)) & 0xFF;
|
||||
ROM[4] = (intROM >> (3*8)) & 0xFF;
|
||||
ROM[5] = (intROM >> (2*8)) & 0xFF;
|
||||
ROM[6] = (intROM >> (1*8)) & 0xFF;
|
||||
ROM[7] = (intROM) & 0xFF;
|
||||
|
||||
|
||||
uint8_t comparebytes = DALLAS_ROM_SIZE;
|
||||
for(int i = 0; i < DS18B20_DEVICE_AMOUNT; 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)
|
||||
{
|
||||
sensor->sensROM = &DS.DevAddr[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
||||
|
||||
if(comparebytes == 0)
|
||||
{
|
||||
result = Dallas_IsConnected(sensor);
|
||||
if(result != HAL_OK)
|
||||
return result;
|
||||
|
||||
sensor->isInitialized = 1;
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Èíèöèàëèçèðóåò ñòðóêòóðó äàò÷èêà ïî ïîëüçîâàòåëüñêèì áàéòàì
|
||||
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
|
||||
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
|
||||
* @param UserBytes34 Ïîëüçîâàòåëüñêèå áàéòû 3 è 4, NULL äëÿ èãíîðà
|
||||
* @param UserBytes12 Ïîëüçîâàòåëüñêèå áàéòû 1 è 2, NULL äëÿ èãíîðà
|
||||
* @retval HAL Status
|
||||
* @details ñòàðøèé áàéò - UserByte4/UserByte2, ìëàäøèé - UserByte3/UserByte1.
|
||||
*/
|
||||
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint16_t UserBytes34, uint16_t UserBytes12)
|
||||
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint16_t UserBytes12, uint16_t UserBytes34)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
sensor->isInitialized = 0;
|
||||
|
||||
if(onewire == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
sensor->onewire = onewire;
|
||||
|
||||
uint8_t UserByte1 = UserBytes12 & 0xFF;
|
||||
uint8_t UserByte2 = UserBytes12 >> 8;
|
||||
uint8_t UserByte3 = UserBytes34 & 0xFF;
|
||||
uint8_t UserByte4 = UserBytes34 >> 8;
|
||||
uint8_t UserByte12Cmp = 0;
|
||||
uint8_t UserByte34Cmp = 0;
|
||||
|
||||
if(onewire == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
|
||||
for(int i = 0; i < DS18B20_DEVICE_AMOUNT; i++)
|
||||
{
|
||||
UserByte12Cmp = 0; UserByte34Cmp = 0;
|
||||
sensor->sensROM = &DS.DevAddr[i];
|
||||
sensor->onewire = onewire;
|
||||
|
||||
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
||||
result = Dallas_IsConnected(sensor);
|
||||
@@ -135,6 +218,7 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_Handle
|
||||
/* Åñëè íàøëè íóæíûé äàò÷èê - çàâåðøàåì ïîèñê */
|
||||
if(UserByte12Cmp && UserByte34Cmp)
|
||||
{
|
||||
sensor->isInitialized = 1;
|
||||
return HAL_OK;
|
||||
}
|
||||
}
|
||||
@@ -154,20 +238,22 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_Handle
|
||||
HAL_StatusTypeDef Dallas_SensorInitByInd(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint8_t sens_ind)
|
||||
{
|
||||
HAL_StatusTypeDef result;
|
||||
sensor->isInitialized = 0;
|
||||
|
||||
if(onewire == NULL)
|
||||
return HAL_ERROR;
|
||||
if(sensor == NULL)
|
||||
return HAL_ERROR;
|
||||
return HAL_ERROR;
|
||||
sensor->onewire = onewire;
|
||||
|
||||
sensor->sensROM = &DS.DevAddr[sens_ind];
|
||||
sensor->onewire = onewire;
|
||||
|
||||
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
|
||||
result = Dallas_IsConnected(sensor);
|
||||
if (result != HAL_OK)
|
||||
return result;
|
||||
|
||||
sensor->isInitialized = 1;
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user