uint8_t ow_rom_search( uint8_t diff, uint8_t *id ) { uint8_t i, j, next_diff; uint8_t b; if( ow_reset() ) { return OW_PRESENCE_ERR; // error, no device found <--- early exit! } ow_byte_wr( OW_SEARCH_ROM ); // ROM search command next_diff = OW_LAST_DEVICE; // unchanged on last device i = OW_ROMCODE_SIZE * 8; // 8 bytes do { j = 8; // 8 bits do { b = ow_bit_io( 1 ); // read bit if( ow_bit_io( 1 ) ) { // read complement bit if( b ) { // 0b11 return OW_DATA_ERR; // data error <--- early exit! } } else { if( !b ) { // 0b00 = 2 devices if( diff > i || ((*id & 1) && diff != i) ) { b = 1; // now 1 next_diff = i; // next pass 0 } } } ow_bit_io( b ); // write bit *id >>= 1; if( b ) { *id |= 0x80; // store bit } i--; } while( --j ); id++; // next byte } while( i ); return next_diff; // to continue search }
/* get power status of DS18x20 input : id = rom_code returns: DS18X20_POWER_EXTERN or DS18X20_POWER_PARASITE */ uint8_t DS18X20_get_power_status(uint8_t id[]) { uint8_t pstat; ow_reset(); ow_command(DS18X20_READ_POWER_SUPPLY, id); pstat=ow_bit_io(1); // pstat 0=is parasite/ !=0 ext. powered ow_reset(); return (pstat) ? DS18X20_POWER_EXTERN:DS18X20_POWER_PARASITE; }
uint8_t ow_byte_wr( uint8_t b ) { uint8_t i = 8, j; do { j = ow_bit_io( b & 1 ); b >>= 1; if( j ) b |= 0x80; } while( --i ); return b; }
/*************************************** * * -***************************************/ uint8_t ow_rom_search( uint8_t diff, uint8_t *id ) { uint8_t i, j, next_diff; uint8_t b; if( ow_reset() ) return OW_PRESENCE_ERR;/* error, no device found*/ ow_byte_wr( OW_SEARCH_ROM ); /*ROM search command*/ next_diff = OW_LAST_DEVICE; /* unchanged on last device*/ i = OW_ROMCODE_SIZE * 8; /* 8 bytes*/ do { j = 8; /* 8 bits*/ do{ b = ow_bit_io( 1 ); /* read bit*/ if( ow_bit_io( 1 ) ) { /* read complement bit*/ if( b )/* 11*/ return OW_DATA_ERR; /* data error*/ } else { if( !b ) { /* 00 = 2 devices*/ if( diff > i || ((*id & 1) && diff != i) ) { b = 1; /* now 1*/ next_diff = i; /* next pass 0*/ } } } ow_bit_io( b ); /* write bit*/ *id >>= 1; if( b ) *id |= 0x80;/* store bit*/ i--; } while( --j ); id++; /* next byte*/ } while( i ); /* to continue search*/ return next_diff; }
u8 ow_byte_write(u8 b) { u8 i; for(i=8; i; i--) { u8 j; j = ow_bit_io(b&1); delay_us(5); b >>= 1; if (j) { b |= 0x80; } } return b; }