12 #include <avr/pgmspace.h>
13 #include <util/delay.h>
14 #include <avr/interrupt.h>
15 #include <util/atomic.h>
22 ONEWIRE_PORT &= ~ONEWIRE_MASK;
23 ONEWIRE_DDR |= ONEWIRE_MASK;
26 uint8_t sreg_tmp=SREG; cli();
27 ONEWIRE_DDR &= ~ONEWIRE_MASK;
29 if( (ONEWIRE_PIN & ONEWIRE_MASK)) {
36 if( !(ONEWIRE_PIN & ONEWIRE_MASK)) {
45 uint8_t sreg_tmp=SREG; cli();
47 ONEWIRE_PORT &= ~ONEWIRE_MASK;
48 ONEWIRE_DDR |= ONEWIRE_MASK;
50 ONEWIRE_DDR &= ~ONEWIRE_MASK;
53 ONEWIRE_PORT &= ~ONEWIRE_MASK;
54 ONEWIRE_DDR |= ONEWIRE_MASK;
56 ONEWIRE_DDR &= ~ONEWIRE_MASK;
67 uint8_t sreg_tmp=SREG; cli();
69 ONEWIRE_PORT &= ~ONEWIRE_MASK;
70 ONEWIRE_DDR |= ONEWIRE_MASK;
72 ONEWIRE_DDR &= ~ONEWIRE_MASK;
74 rebit = ONEWIRE_PIN & ONEWIRE_MASK;
101 for (i=0; i<8; i++) {
110 memset(buffer, 0, 8);
123 uint8_t mask, i, j, bit, rom_tmp;
124 uint8_t max_conf_zero=0;
125 static uint8_t max_conf_old;
126 uint8_t branch_flag=0;
128 if (buffer == NULL) {
141 for(j=0; j<64; j++) {
147 if (j < max_conf_old) {
148 if (rom_tmp & mask) {
155 }
else if (j == max_conf_old) {
198 max_conf_old = max_conf_zero;
209 uint8_t mask, tmp=0, i, j;
217 for (j=0; j<64; j++) {
246 uint8_t mask=1, tmp=0, i=0, j;
252 for (j=0; j<64; j++) {
304 static const uint8_t crc_table[16] PROGMEM =
305 {0x00, 0x9D, 0x23, 0xBE, 0x46, 0xDB, 0x65, 0xF8,
306 0x8C, 0x11, 0xAF, 0x32, 0xCA, 0x57, 0xE9, 0x74};
317 for(; cnt>0; cnt--) {
321 crc = (crc >> 4) | (tmp << 4);
322 crc ^= pgm_read_byte(&crc_table[i]);
325 crc = (crc >> 4) | (tmp & 0xF0);
326 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