The DS18B20 is a digital temperature sensor supplying a unique 48-bit serial number accessed through the 1-wire bus protocol.
main.c
#if ! (BSP430_CONSOLE - 0)
#error Console is not configured correctly
#endif
#if ! (BSP430_UPTIME - 0)
#error Uptime is not configured correctly
#endif
#ifndef APP_DS18B20_BUS
#define APP_DS18B20_BUS ds18b20
.
port = APP_DS18B20_PORT_HAL,
.bit = APP_DS18B20_BIT,
};
#endif
#ifndef APP_DS18B20_POWER_BIT
#define APP_DS18B20_POWER_BIT 0
#endif
void main ()
{
int rc;
int external_power;
static const char * const supply_type[] = { "parasitic", "external" };
cprintf(
"Uptime now %lu with frequency %lu Hz\n",
cprintf(
"Monitoring DS18xx on %s.%u ; ",
if (APP_DS18B20_POWER_BIT) {
cprintf(
"parasitic conversion power from %s.%u\n",
} else {
cprintf(
"no parasitic power boost\n");
}
cprintf(
"Power supply: %s\n", supply_type[external_power]);
if (0 > external_power) {
cprintf(
"ERROR: Device not present?\n");
} else if ((! external_power) && (! (APP_DS18B20_POWER_BIT))) {
cprintf(
"ERROR: Parasitic power without conversion boost?\n");
}
do {
if (0 != rc) {
cprintf(
"ERROR: Failed to read serial number from DS18B20: %d\n", rc);
}
} while (0 != rc);
cprintf(
"DS18B20 serial number: %02x%02x%02x%02x%02x%02x\n",
serial.id[0], serial.id[1], serial.id[2],
serial.id[3], serial.id[4], serial.id[5]);
while (1) {
int rc;
unsigned long start_tck;
unsigned long end_tck;
unsigned int duration_ms;
int t_c;
rc = -1;
if (external_power) {
}
} else {
}
}
if (0 == rc) {
cprintf(
"Temperature %d dCel or %d d[degF] in %u ms\n",
duration_ms);
} else {
cprintf(
"Measurement failed in %u ms\n", duration_ms);
}
}
}
bsp430_config.h
#define BSP430_PLATFORM_BOOT_CONFIGURE_LFXT1 1
#ifndef configBSP430_PLATFORM_SPIN_FOR_JUMPER
#define configBSP430_PLATFORM_SPIN_FOR_JUMPER 1
#endif
#define configBSP430_CONSOLE 1
#define configBSP430_UPTIME 1
#define configBSP430_UPTIME_DELAY 1
#if (BSP430_PLATFORM_SURF - 0)
#define configBSP430_PLATFORM_SURF_DS1825 1
#define APP_DS18B20_BUS xBSP430surfDS1825
#elif (BSP430_PLATFORM_EXP430F5529 - 0)
#define APP_DS18B20_PORT_HAL BSP430_HAL_PORT7
#define APP_DS18B20_BIT BIT7
#ifndef APP_DS18B20_POWER_BIT
#define APP_DS18B20_POWER_BIT BIT1
#endif
#define configBSP430_HAL_PORT7 1
#else
#define APP_DS18B20_PORT_HAL BSP430_HAL_PORT1
#define APP_DS18B20_BIT BIT6
#ifndef APP_DS18B20_POWER_BIT
#define APP_DS18B20_POWER_BIT BIT4
#endif
#define configBSP430_HAL_PORT1 1
#endif
Makefile
PLATFORM ?= exp430fr5739
MODULES=$(MODULES_PLATFORM)
MODULES += $(MODULES_CONSOLE) $(MODULES_UPTIME)
MODULES += periph/port utility/onewire
SRC=main.c
include $(BSP430_ROOT)/make/Makefile.common