int main() { lcd_init(); while(1) { if(!OW_reset()) { OW_send_byte(0xCC); OW_send_byte(0x44); _delay_ms(750); if(!OW_reset()) { OW_send_byte(0xCC); OW_send_byte(0xBE); //chcemy odczytac zawartosc pamieci uint8_t x = OW_read_byte(); uint8_t y = OW_read_byte(); //sklejamy x, y uint16_t z = (y<<8) | x; lcd_set_xy(0, 0); fprintf(&lcd_stream, "%d.%04d deg C", z>>4, (z&0x0F)*625); lcd_set_xy(0, 1); fprintf(&lcd_stream, "dbg %d %d", x, y); } }
static ZERO_OR_ERROR FS_r_mem(struct one_wire_query *owq) { /* read is consecutive, unchecked. No paging */ ZERO_OR_ERROR read_status = COMMON_read_memory_F0(owq, 0, 0) ; OW_reset(PN(owq)) ; // DS2404 needs this to release for 3-wire communication return read_status ; }
static ZERO_OR_ERROR FS_reset(struct one_wire_query *owq) { if ( OWQ_Y(owq) == 0 ) { return 0 ; } FS_del_sibling( "counter/cycles", owq ) ; return GB_to_Z_OR_E (OW_reset( PN(owq) )) ; }
static ZERO_OR_ERROR FS_w_mem(struct one_wire_query *owq) { size_t pagesize = 32; ZERO_OR_ERROR error_code = COMMON_readwrite_paged(owq, 0, pagesize, OW_w_mem) ; /* paged write */ if (error_code != 0) { error_code = -EFAULT ; } OW_reset(PN(owq)) ; // DS2404 needs this to release for 3-wire communication return error_code ; }
uint8_t DS18X20_recall_E2( uint8_t id[] ) { OW_reset(); //** if( OW_input_pin_state() ) { // only send if bus is "idle" = high OW_command( DS18X20_RECALL_E2, id ); // TODO: wait until status is "1" (then eeprom values // have been copied). here simple delay to avoid timeout // handling delayms(DS18X20_COPYSP_DELAY); return DS18X20_OK; } else { return DS18X20_ERROR; } }
uint8_t DS18X20_copy_scratchpad( uint8_t with_power_extern, uint8_t id[] ) { OW_reset(); //** if( OW_input_pin_state() ) { // only send if bus is "idle" = high OW_command( DS18X20_COPY_SCRATCHPAD, id ); if (with_power_extern != DS18X20_POWER_EXTERN) OW_parasite_enable(); delayms(DS18X20_COPYSP_DELAY); // wait for 10 ms if (with_power_extern != DS18X20_POWER_EXTERN) OW_parasite_disable(); return DS18X20_OK; } else { return DS18X20_START_FAIL; } }