uint8_t noinline reset_onewire(uint8_t busmask) { /* pull bus low */ OW_CONFIG_OUTPUT(busmask); OW_LOW(busmask); /* wait 480us */ _delay_loop_2(OW_RESET_TIMEOUT_1); /* release bus */ OW_CONFIG_INPUT(busmask); /* wait 60us (maximal pause) + 30 us (half minimum pulse) */ _delay_loop_2(OW_RESET_TIMEOUT_2); /* sample data */ uint8_t data1 = OW_GET_INPUT(busmask); /* wait 390us */ _delay_loop_2(OW_RESET_TIMEOUT_3); /* sample data again */ uint8_t data2 = OW_GET_INPUT(busmask); /* if first sample is low and second sample is high, at least one device is * attached to this bus */ return (uint8_t)(~data1 & data2 & busmask); }
uint8_t noinline ow_read(uint8_t busmask) { /* a read timeslot is sent by holding the data line low for * 1us, then wait approximately 14us, then sample data and * wait */ /* this is also used as ow_write_1, as the only difference * is that the return value is discarded */ OW_CONFIG_OUTPUT(busmask); OW_LOW(busmask); _delay_loop_2(OW_READ_TIMEOUT_1); OW_HIGH(busmask); OW_CONFIG_INPUT(busmask); _delay_loop_2(OW_READ_TIMEOUT_2); /* sample data now */ uint8_t data = (uint8_t)(OW_GET_INPUT(busmask) > 0); /* wait for remaining slot time */ _delay_loop_2(OW_READ_TIMEOUT_3); OW_CONFIG_OUTPUT(busmask); return data; }
void onewire_init(void) { /* configure onewire pin as input */ OW_CONFIG_INPUT(ONEWIRE_BUSMASK); /* release lock */ ow_global.lock = 0; }
void onewire_init(void) { /* configure onewire pin as input */ OW_CONFIG_INPUT(ONEWIRE_BUSMASK); /* release lock */ ow_global.lock = 0; /* initialize sensor data */ memset(ow_sensors, 0, OW_SENSORS_COUNT * sizeof(ow_sensor_t)); #ifdef ONEWIRE_NAMING_SUPPORT /* restore sensor names */ ow_names_restore(); #endif }