38 #include "dev/temp-sensor.h"
39 #include <util/delay_basic.h>
40 #define delay_us(us) (_delay_loop_2(1 + (us * F_CPU) / 4000000UL))
42 const struct sensors_sensor temp_mcu_sensor;
74 result = !OW_GET_PIN_STATE();
81 result = OW_GET_PIN_STATE();
88 write_bit(uint8_t bit)
139 bit = OW_GET_PIN_STATE();
163 for(i = 0; i < 8; i++) {
165 result += (bit << i);
172 write_byte(uint8_t byte)
176 for(i = 0; i < 8; i++) {
177 write_bit((byte >> i) & 1);
185 ds18b20_get_temp(
double *temp)
190 if(ds18b20_probe()) {
192 write_byte(DS18B20_COMMAND_SKIP_ROM);
195 write_byte(DS18B20_COMMAND_START_CONVERSION);
203 while(!OW_GET_PIN_STATE()) {
217 (void)ds18b20_probe();
218 write_byte(DS18B20_COMMAND_SKIP_ROM);
219 write_byte(DS18B20_COMMAND_READ_SCRATCH_PAD);
220 uint8_t i, sp_arr[9];
221 for(i = 0; i < 9; i++) {
222 sp_arr[i] = read_byte();
226 uint8_t crc_cal = crc8_ds18b20(sp_arr, 8);
228 if(crc_cal != sp_arr[8]) {
236 uint8_t temp_lsb = sp_arr[0];
237 uint8_t temp_msb = sp_arr[1];
239 temp_res = (int16_t)temp_msb << 8 | temp_lsb;
240 *temp = (double)temp_res * 0.0625;
250 crc8_ds18b20(uint8_t *buf, uint8_t buf_len)
255 for(i = 0; i < buf_len; i++) {
256 result = result ^ buf[i];
257 for(b = 1; b < 9; b++) {
259 result = (result >> 1) ^ 0x8C;
261 result = result >> 1;
272 ret = ds18b20_get_temp(&t);
276 return (
int) (t * 100);
282 configure(
int type,
int c)
292 SENSORS_SENSOR(temp_sensor, TEMP_SENSOR, value, configure, status);
void clock_delay_msec(uint16_t howlong)
Delay up to 65535 milliseconds.
static volatile clock_time_t count
These routines define the AVR-specific calls declared in /core/sys/clock.h CLOCK_SECOND is the number...
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.