Files
templates/c/ds18b20-ds2480/examples/read_first.c

26 lines
1.1 KiB
C

/*
* Минимальный блокирующий пример: подготовить мост DS2480B, найти первый датчик, запустить
* преобразование и прочитать температуру. Обратные вызовы UART и задержек предоставляет плата;
* ожидание преобразования входит во время вызова.
*/
#include "ds18b20_ds2480.h"
/* board_port supplies the four callbacks documented in ds2480.h.
* Blocking example: includes bridge reset, scan and 750 ms conversion.
*/
ds2480_status ds18b20_example_read_first(const ds2480_port *board_port, int16_t *raw)
{
ds2480 bus;
ds2480_search search = {{0}, 0, 0};
ds2480_status status;
if (!raw) return DS2480_ARGUMENT;
status = ds2480_init(&bus, board_port, 20);
if (status != DS2480_OK) return status;
status = ds18b20_ds2480_next(&bus, &search);
if (status != DS2480_OK) return status;
status = ds18b20_ds2480_convert(&bus, search.rom);
if (status != DS2480_OK) return status;
return ds18b20_ds2480_temperature(&bus, search.rom, raw);
}