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  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  You can contact the author at Falk.Brunner@gmx.de
22 
23 *****************************************************************************/
24 
58 #ifndef ONEWIRE_H_
59 #define ONEWIRE_H_
60 
61 #include <avr/io.h>
62 
67 #define ONEWIRE_BIT PA0
68 #define ONEWIRE_PIN PINA
69 #define ONEWIRE_PORT PORTA
70 #define ONEWIRE_DDR DDRA
71 
77 #define ONEWIRE_STRONG_PU_ON ONEWIRE_PORT |= ONEWIRE_MASK; ONEWIRE_DDR |= ONEWIRE_MASK;
78 #define ONEWIRE_STRONG_PU_OFF ONEWIRE_DDR &= ~ONEWIRE_MASK;
79 
85 #define ONEWIRE_MASK (1<<ONEWIRE_BIT)
86 
92 #define ONEWIRE_MATCH_ROM 0x55
93 #define ONEWIRE_SEARCH_ROM 0xF0
94 #define ONEWIRE_SKIP_ROM 0xCC
95 #define ONEWIRE_READ_ROM 0x33
96 #define ONEWIRE_ALARM_SEARCH 0xEC
97 
103 
114 uint8_t onewire_reset(void);
115 
122 uint8_t onewire_read_byte(void);
123 
130 void onewire_write_byte(uint8_t data);
131 
138 void onewire_search_init(uint8_t buffer[8]);
139 
152 uint8_t onewire_alarm_search(uint8_t buffer[8]);
153 
166 uint8_t onewire_search_rom(uint8_t buffer[8]);
167 
176 uint8_t onewire_match_rom(const uint8_t rom[8]);
177 
188 uint8_t onewire_read_rom(uint8_t rom[8]);
189 
199 uint8_t onewire_skip_rom(void);
200 
208 uint8_t onewire_crc(const uint8_t *data, uint8_t cnt);
209 
215 
222 void onewire_write_bit(uint8_t data);
223 
230 uint8_t onewire_read_bit(void);
231 
245 uint8_t onewire_search(uint8_t buffer[8], uint8_t cmd);
246 
247 #endif
uint8_t onewire_reset(void)
OneWire reset.
Definition: onewire.c:19
uint8_t onewire_match_rom(const uint8_t rom[8])
select device on bus
Definition: onewire.c:208
void onewire_write_byte(uint8_t data)
write one byte
Definition: onewire.c:98
uint8_t onewire_read_rom(uint8_t rom[8])
read ROM of device
Definition: onewire.c:245
void onewire_search_init(uint8_t buffer[8])
init rom search buffer and internal variables
Definition: onewire.c:109
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.c:303
void onewire_write_bit(uint8_t data)
write one bit to bus
Definition: onewire.c:42
uint8_t onewire_search(uint8_t buffer[8], uint8_t cmd)
scan OneWire bus for normal ROM or alarm search
Definition: onewire.c:122
uint8_t onewire_skip_rom(void)
select device on bus
Definition: onewire.c:236
uint8_t onewire_read_bit(void)
read one bit from bus
Definition: onewire.c:63
uint8_t onewire_read_byte(void)
read one byte
Definition: onewire.c:85
uint8_t onewire_alarm_search(uint8_t buffer[8])
scan OneWire bus for devices with active alarm flag
Definition: onewire.c:118
uint8_t onewire_search_rom(uint8_t buffer[8])
scan OneWire bus for ROMs
Definition: onewire.c:114