20 #include <avr/pgmspace.h>
21 #include <util/delay.h>
22 #include <avr/interrupt.h>
23 #include <util/atomic.h>
28 uint8_t err=ONEWIRE_OK;
30 ONEWIRE_PORT &= ~ONEWIRE_MASK;
31 ONEWIRE_DDR |= ONEWIRE_MASK;
34 uint8_t sreg_tmp=SREG; cli();
35 ONEWIRE_DDR &= ~ONEWIRE_MASK;
37 if( (ONEWIRE_PIN & ONEWIRE_MASK)) {
38 err = ONEWIRE_NO_PRESENCE;
44 if( !(ONEWIRE_PIN & ONEWIRE_MASK)) {
45 err = ONEWIRE_GND_SHORT;
53 uint8_t sreg_tmp=SREG; cli();
55 ONEWIRE_PORT &= ~ONEWIRE_MASK;
56 ONEWIRE_DDR |= ONEWIRE_MASK;
58 ONEWIRE_DDR &= ~ONEWIRE_MASK;
61 ONEWIRE_PORT &= ~ONEWIRE_MASK;
62 ONEWIRE_DDR |= ONEWIRE_MASK;
64 ONEWIRE_DDR &= ~ONEWIRE_MASK;
75 uint8_t sreg_tmp=SREG; cli();
77 ONEWIRE_PORT &= ~ONEWIRE_MASK;
78 ONEWIRE_DDR |= ONEWIRE_MASK;
80 ONEWIRE_DDR &= ~ONEWIRE_MASK;
82 rebit = ONEWIRE_PIN & ONEWIRE_MASK;
109 for (i=0; i<8; i++) {
118 memset(buffer, 0, 8);
131 uint8_t mask, i, j, bit, rom_tmp;
132 uint8_t max_conf_zero=0;
133 static uint8_t max_conf_old;
134 uint8_t branch_flag=0;
136 if (buffer == NULL) {
142 return ONEWIRE_NO_PRESENCE;
149 for(j=0; j<64; j++) {
155 if (j < max_conf_old) {
156 if (rom_tmp & mask) {
163 }
else if (j == max_conf_old) {
180 return ONEWIRE_SCAN_ERROR;
206 max_conf_old = max_conf_zero;
209 return ONEWIRE_CRC_ERROR;
210 }
else if (branch_flag) {
213 return ONEWIRE_LAST_CODE;
218 uint8_t mask, tmp=0, i, j;
221 return ONEWIRE_NO_PRESENCE;
226 for (j=0; j<64; j++) {
247 return ONEWIRE_NO_PRESENCE;
255 uint8_t mask=1, tmp=0, i=0, j;
258 return ONEWIRE_NO_PRESENCE;
261 for (j=0; j<64; j++) {
313 static const uint8_t crc_table[16] PROGMEM =
314 {0x00, 0x9D, 0x23, 0xBE, 0x46, 0xDB, 0x65, 0xF8,
315 0x8C, 0x11, 0xAF, 0x32, 0xCA, 0x57, 0xE9, 0x74};
326 for(; cnt>0; cnt--) {
330 crc = (crc >> 4) | (tmp << 4);
331 crc ^= pgm_read_byte(&crc_table[i]);
334 crc = (crc >> 4) | (tmp & 0xF0);
335 crc ^= pgm_read_byte(&crc_table[i]);
uint8_t onewire_reset(void)
OneWire reset.
uint8_t onewire_match_rom(const uint8_t rom[8])
select device on bus
void onewire_write_byte(uint8_t data)
write one byte
uint8_t onewire_read_rom(uint8_t rom[8])
read ROM of device
void onewire_search_init(uint8_t buffer[8])
init rom search buffer and internal variables
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 onewire_write_bit(uint8_t wrbit)
write one bit to bus
uint8_t onewire_search(uint8_t buffer[8], uint8_t cmd)
scan OneWire bus for normal ROM or alarm search
uint8_t onewire_skip_rom(void)
select device on bus
uint8_t onewire_read_bit(void)
read one bit from bus
uint8_t onewire_read_byte(void)
read one byte
uint8_t onewire_alarm_search(uint8_t buffer[8])
scan OneWire bus for devices with active alarm flag
uint8_t onewire_search_rom(uint8_t buffer[8])
scan OneWire bus for ROMs