18 #include <util/delay.h>
19 #include <avr/interrupt.h>
20 #include <util/atomic.h>
27 if (parasitic_power) {
28 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
39 uint8_t scratchpad[9];
43 return ONEWIRE_CRC_ERROR;
46 temp = ((int16_t)scratchpad[1] << 8) | scratchpad[0];
48 switch((scratchpad[4] >> 5) & 3) {
49 case 0: temp &= ~7;
break;
50 case 1: temp &= ~3;
break;
51 case 2: temp &= ~1;
break;
55 *temperature = (temp * 10) >> 4;
61 uint8_t scratchpad[9];
65 return ONEWIRE_CRC_ERROR;
68 temp = ((int16_t)scratchpad[1] << 8) | scratchpad[0];
73 temp = temp - 4 + (16-scratchpad[6]);
76 *temperature = (temp * 10) >> 4;
102 switch(adc_resolution) {
103 case 9: cfg = 0x00;
break;
104 case 10: cfg = 0x20;
break;
105 case 11: cfg = 0x40;
break;
106 default: cfg = 0x60;
break;
113 if (parasitic_power) {
114 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
122 ONEWIRE_STRONG_PU_OFF
void ds18x20_convert_t(uint8_t parasitic_power)
start temperature conversion
void ds18B20_write_scratchpad(int8_t tl, int8_t th, uint8_t adc_resolution)
write tl, th and configuration of DS18B20
uint8_t ds18S20_read_temp(int16_t *temperature)
Read temperature from DS18S20 (9 bit + enhanced resolution, effective 12 bits)
void onewire_write_byte(uint8_t data)
write one byte
uint8_t onewire_crc(const uint8_t *data, uint8_t cnt)
calculate CRC over data array, fast version, 0.3ms for 8 bytes @1MHz
void ds18S20_write_scratchpad(int8_t tl, int8_t th)
write tl and th of DS18S20
uint8_t onewire_read_bit(void)
read one bit from bus
uint8_t onewire_read_byte(void)
read one byte
void ds18x20_copy_scratchpad(uint8_t parasitic_power)
copy scratchpad to EEPROM, busy waiting (10ms),
uint8_t ds18B20_read_temp(int16_t *temperature)
Read temperature from DS18B20 (9-12 bit resolution)
uint8_t ds18x20_read_power_supply(void)
read power supply
void ds18x20_recall_E2(void)
copy EEPROM to scratchpad, busy waiting (1ms)
void ds18x20_read_scratchpad(uint8_t *buffer)
Read complete scratchpad of DS18x20 (9 bytes)