OneWire + DS18X20 Library
Basic functions for OneWire operations + specific DS18x20 operations
 All Functions Groups Pages
onewire.h
1 /*****************************************************************************
2 
3  OneWire (tm) library
4 
5  Copyright (C) 2016 Falk Brunner
6 
7 *****************************************************************************/
8 
9 /*
10 * ----------------------------------------------------------------------------
11 * "THE BEER-WARE LICENSE" (Revision 42):
12 * <Falk.Brunner@gmx.de> wrote this file. As long as you retain this notice you
13 * can do whatever you want with this stuff. If we meet some day, and you think
14 * this stuff is worth it, you can buy me a beer in return. Falk Brunner
15 * ----------------------------------------------------------------------------
16 */
17 
51 #ifndef ONEWIRE_H_
52 #define ONEWIRE_H_
53 
54 #include <avr/io.h>
55 
60 #define ONEWIRE_BIT PA0
61 #define ONEWIRE_PIN PINA
62 #define ONEWIRE_PORT PORTA
63 #define ONEWIRE_DDR DDRA
64 
70 #define ONEWIRE_STRONG_PU_ON ONEWIRE_PORT |= ONEWIRE_MASK; ONEWIRE_DDR |= ONEWIRE_MASK;
71 #define ONEWIRE_STRONG_PU_OFF ONEWIRE_DDR &= ~ONEWIRE_MASK;
72 
78 #define ONEWIRE_MASK (1<<ONEWIRE_BIT)
79 
85 #define ONEWIRE_MATCH_ROM 0x55
86 #define ONEWIRE_SEARCH_ROM 0xF0
87 #define ONEWIRE_SKIP_ROM 0xCC
88 #define ONEWIRE_READ_ROM 0x33
89 #define ONEWIRE_ALARM_SEARCH 0xEC
90 
96 #define ONEWIRE_OK 0 // no error
97 #define ONEWIRE_NO_PRESENCE 1 // no presence pulse detected during onewire reset
98 #define ONEWIRE_CRC_ERROR 2 // crc error in data reception
99 #define ONEWIRE_SCAN_ERROR 3 // scan error during ROM scan
100 #define ONEWIRE_LAST_CODE 4 // last rom code scanned (no error, just info)
101 #define ONEWIRE_GND_SHORT 5 // bus short circuit to GND
102 
108 
119 uint8_t onewire_reset(void);
120 
127 uint8_t onewire_read_byte(void);
128 
135 void onewire_write_byte(uint8_t data);
136 
143 void onewire_search_init(uint8_t buffer[8]);
144 
158 uint8_t onewire_alarm_search(uint8_t buffer[8]);
159 
173 uint8_t onewire_search_rom(uint8_t buffer[8]);
174 
183 uint8_t onewire_match_rom(const uint8_t rom[8]);
184 
196 uint8_t onewire_read_rom(uint8_t rom[8]);
197 
208 uint8_t onewire_skip_rom(void);
209 
221 uint8_t onewire_crc(const uint8_t *data, uint8_t cnt);
222 
228 
235 void onewire_write_bit(uint8_t data);
236 
243 uint8_t onewire_read_bit(void);
244 
259 uint8_t onewire_search(uint8_t buffer[8], uint8_t cmd);
260 
261 #endif
uint8_t onewire_reset(void)
OneWire reset.
Definition: onewire.cpp:27
uint8_t onewire_match_rom(const uint8_t rom[8])
select device on bus
Definition: onewire.cpp:211
void onewire_write_byte(uint8_t data)
write one byte
Definition: onewire.cpp:100
uint8_t onewire_read_rom(uint8_t rom[8])
read ROM ID of device
Definition: onewire.cpp:238
void onewire_search_init(uint8_t buffer[8])
init rom search buffer and internal variables
Definition: onewire.cpp:111
uint8_t onewire_crc(const uint8_t *data, uint8_t cnt)
calculate CRC over data array, fast version, 0.3ms for 8 bytes @1MHz
Definition: onewire.cpp:287
void onewire_write_bit(uint8_t data)
write one bit to bus
Definition: onewire.cpp:48
uint8_t onewire_search(uint8_t buffer[8], uint8_t cmd)
scan OneWire bus for normal ROM or alarm search
Definition: onewire.cpp:124
uint8_t onewire_skip_rom(void)
select device on bus
Definition: onewire.cpp:226
uint8_t onewire_read_bit(void)
read one bit from bus
Definition: onewire.cpp:67
uint8_t onewire_read_byte(void)
read one byte
Definition: onewire.cpp:87
uint8_t onewire_alarm_search(uint8_t buffer[8])
scan OneWire bus for devices with active alarm flag
Definition: onewire.cpp:120
uint8_t onewire_search_rom(uint8_t buffer[8])
scan OneWire bus for ROMs
Definition: onewire.cpp:116