Добавлен функция скана всех сенсоров на линии через модбас

Заполнение респонса в модбас выведено в отдельную функцию
This commit is contained in:
2025-03-05 10:07:05 +03:00
parent 932a6cc8e0
commit 28749c63e8
11 changed files with 241 additions and 100 deletions

View File

@@ -112,7 +112,7 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_S
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])
if(hdallas->ds_devices->DevAddr[i][rom_byte] == ROM[rom_byte])
comparebytes--;
}
if(comparebytes == 0)
@@ -126,7 +126,7 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(DALLAS_HandleTypeDef *hdallas, DALLAS_S
if(comparebytes == 0)
{
result = Dallas_SensorInit(hdallas, sensor, &DS.DevAddr[ROM_ind]);
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[ROM_ind]);
return result;
}
else
@@ -164,7 +164,7 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DA
for(int i = 0; i < hdallas->onewire->RomCnt; i++)
{
/* Проверка присутствует ли выбранный датчик на линии */
result = DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&hdallas->scratchpad);
result = DS18B20_ReadScratchpad(hdallas->onewire, (uint8_t *)&hdallas->ds_devices->DevAddr[i], (uint8_t *)&hdallas->scratchpad);
if (result != HAL_OK)
return result;
@@ -199,7 +199,7 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(DALLAS_HandleTypeDef *hdallas, DA
{
// sensor->isInitialized = 1;
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
result = Dallas_SensorInit(hdallas, sensor, &DS.DevAddr[i]);
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[i]);
return result;
}
}
@@ -226,7 +226,7 @@ HAL_StatusTypeDef Dallas_SensorInitByInd(DALLAS_HandleTypeDef *hdallas, DALLAS_S
if(sensor == NULL)
return HAL_ERROR;
result = Dallas_SensorInit(hdallas, sensor, &DS.DevAddr[sensor->Init.InitParam]);
result = Dallas_SensorInit(hdallas, sensor, &hdallas->ds_devices->DevAddr[sensor->Init.InitParam]);
return result;
}

View File

@@ -82,6 +82,7 @@ typedef struct __packed
typedef struct
{
OneWire_t *onewire;
DS18B20_Drv_t *ds_devices;
DALLAS_ScratchpadTypeDef scratchpad;
}DALLAS_HandleTypeDef;
extern DALLAS_HandleTypeDef hdallas1;

View File

@@ -77,7 +77,6 @@ typedef enum {
typedef struct
{
uint8_t DevAddr[DS18B20_DEVICE_AMOUNT][8];
DS18B20_Res_t Resolution;
} DS18B20_Drv_t;
extern DS18B20_Drv_t DS;
extern OneWire_t OW;

View File

@@ -16,6 +16,7 @@ void OneWire_WriteBit(OneWire_t* OW, uint8_t bit)
if(OW == NULL)
return;
#ifndef ONEWIRE_UART_H
__disable_irq();
if(bit)
{
/* Set line low */
@@ -46,6 +47,7 @@ void OneWire_WriteBit(OneWire_t* OW, uint8_t bit)
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_WRITE_0_US);
OneWire_Pin_Mode(OW, Input);
}
__enable_irq();
#else
OneWireUART_ProcessBit(onewire_uart, bit);
#endif
@@ -61,6 +63,7 @@ uint8_t OneWire_ReadBit(OneWire_t* OW)
if(OW == NULL)
return 0;
__disable_irq();
uint8_t bit = 0;
#ifndef ONEWIRE_UART_H
/* Line low */
@@ -77,6 +80,7 @@ uint8_t OneWire_ReadBit(OneWire_t* OW)
/* Wait 50us to complete 60us period */
OneWire_Delay_uw(ONEWIRE_COMMAND_SLOT_US - ONEWIRE_READ_CMD_US - ONEWIRE_READ_DELAY_US);
__enable_irq();
#else
bit = OneWireUART_ProcessBit(onewire_uart, 1);
#endif