20 #include <avr/pgmspace.h>
21 #include <util/delay.h>
22 #include <avr/interrupt.h>
23 #include <util/atomic.h>
28 uint8_t rc=ONEWIRE_OK;
32 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
36 rc = ONEWIRE_NO_PRESENCE;
42 rc = ONEWIRE_GND_SHORT;
49 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
67 ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
72 readbit = ONEWIRE_READ;
108 memset(buffer, 0, 8);
121 uint8_t mask, i, j, bit, rom_tmp, rc;
122 uint8_t max_conf_zero=0;
123 static uint8_t max_conf_old;
124 uint8_t branch_flag=0;
126 if (buffer == NULL) {
140 for(j=0; j<64; j++) {
146 if (j < max_conf_old) {
147 if (rom_tmp & mask) {
154 }
else if (j == max_conf_old) {
171 return ONEWIRE_SCAN_ERROR;
197 max_conf_old = max_conf_zero;
200 return ONEWIRE_CRC_ERROR;
201 }
else if (branch_flag) {
204 return ONEWIRE_LAST_CODE;
216 for (i=0; i<8; i++) {
243 for (i=0; i<8; i++) {
248 return ONEWIRE_CRC_ERROR;
288 static const uint8_t crc_table[16] PROGMEM =
289 {0x00, 0x9D, 0x23, 0xBE, 0x46, 0xDB, 0x65, 0xF8,
290 0x8C, 0x11, 0xAF, 0x32, 0xCA, 0x57, 0xE9, 0x74};
292 uint8_t crc, i, tmp, zerocheck;
302 for(; cnt>0; cnt--) {
307 crc = (crc >> 4) | (tmp << 4);
308 crc ^= pgm_read_byte(&crc_table[i]);
311 crc = (crc >> 4) | (tmp & 0xF0);
312 crc ^= pgm_read_byte(&crc_table[i]);
356 uint8_t crc, i, tmp, zerocheck;
357 const uint8_t poly=0x8C;
364 for(; cnt>0; cnt--) {
367 for (i=0; i<8; i++) {
370 if (tmp & 1) crc |= 0x80;
374 if (tmp & 1) crc |= 0x80;
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 ID 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
uint8_t onewire_crc_serial(const uint8_t *data, uint8_t cnt)
calculate CRC over data array, serial version, 1ms 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