static int8_t ow_read_bit(uint8_t i) { uint8_t bit; /* >= 1usec recovery time. */ ow_release(); _delay_us(1); /* >= 1 usec pull low to start read slot. */ /* The read slot is time critical to a few usec, so disable interrupts. */ cli(); ow_low(); _delay_us(1); ow_release(); /* We must read the bus within at most 15 usec from pulling the bus low. The later we read, the more margin. But let's keep a couple usec to account for delays outside of _delay_us(). */ _delay_us(12); bit= ow_read(); sei(); if ((i % 8) == 0) ow_read_buf[i / 8] = 0; if (bit) ow_read_buf[i / 8] |= (1 << (i % 8)); /* Total read slot >= 60 usec. */ ow_delay_us(60-1-12); return 0; }
static int8_t ow_write_bit(uint8_t bit) { ow_release(); /* Min. 1 usec recovery between slots. */ _delay_us(1); if (bit) { /* Write 1: release bus within 1 usec <= T <= 15 usec. */ /* Let's make that 2 usec just to be a bit on the safe side. */ cli(); ow_low(); _delay_us(2); ow_release(); sei(); /* Total write pulse >= 60 usec. */ ow_delay_us(60 - 2); } else { /* Write 0: pull low for 60 usec <= T <= 120 usec. */ ow_low(); ow_delay_us(60); } return 0; }
void ow_write_bit(unsigned char bit) { if (!bit) { ow_drive_low(); delay_microseconds(OW_C); ow_release(); delay_microseconds(OW_D); } else { ow_drive_low(); delay_microseconds(OW_A); ow_release(); delay_microseconds(OW_B); } }
void ow_write_byte(unsigned char data) { unsigned char bitcount; for(bitcount=8; bitcount>0; bitcount--) { if (data & 0x01) { ow_drive_low(); delay_microseconds(OW_A); ow_release(); delay_microseconds(OW_B); } else { ow_drive_low(); delay_microseconds(OW_C); ow_release(); delay_microseconds(OW_D); } data = data >> 1; } }
static int8_t ow_convert_t(uint8_t i) { if (i < 8) return ow_write_bit(0x44 & (1 << i)); else { /* Temperature conversion takes max 750 msec. */ ow_release(); ow_delay_ms(750); return 0; } }
unsigned char ow_read_bit() { unsigned char bit; ow_drive_low(); delay_microseconds(OW_A); ow_release(); delay_microseconds(OW_E); if (ONEWIRE_PORTIN & ONEWIRE_PINMASK){ bit = 1; } else { bit = 0; } delay_microseconds(OW_F); return(bit); }
int ow_reset() { int presence; delay_microseconds( OW_G ); ow_drive_low(); delay_microseconds( OW_H ); ow_release(); delay_microseconds( OW_I ); if(ONEWIRE_PORTIN & ONEWIRE_PINMASK ) { presence = 0; // bus is high, slave did not pull it down } else { presence = 1; // bus is being pulled down, presence detected } delay_microseconds( OW_J ); return ( presence ); // return the sampled presence pulse result }
static int8_t ow_init(uint8_t i) { if (i == 0) { /* Reset pulse: low for >= 480 usec. */ ow_low(); ow_delay_us(480); } else if (i == 1) { /* Presence detect 60 usec <= T <= 240 usec. */ ow_release(); ow_delay_us(60); } else { /* Total presence pulse 480 usec. */ ow_presence= !ow_read(); ow_delay_us(480-60); } return 0; }
unsigned char ow_read_byte() { unsigned char data=0; unsigned char bitcount, bit; for ( bitcount=8; bitcount>0; bitcount-- ) { ow_drive_low(); delay_microseconds(OW_A); ow_release(); delay_microseconds(OW_E); if (ONEWIRE_PORTIN & ONEWIRE_PINMASK){ bit = 1; } else { bit = 0; } delay_microseconds(OW_F); //on 1-wire bus data is sent starting with least significant bit. We need to inert bits from the left and shift. data = data >> 1; data |= (bit << 7); } return(data); }