From ed35d40a612633c3545a6cd7e59e3e432c623dfc Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Sun, 24 Jan 2016 23:10:24 +0100 Subject: actually commit the write --- avr/1wire.c | 10 ++++++++++ avr/1wire.h | 2 ++ avr/main.c | 13 +++++++++++++ 3 files changed, 25 insertions(+) (limited to 'avr') diff --git a/avr/1wire.c b/avr/1wire.c index 54c8dcc..72722df 100644 --- a/avr/1wire.c +++ b/avr/1wire.c @@ -238,6 +238,16 @@ uint8_t ds1992_scratch_verify(uint16_t addr, const uint8_t* buf, uint8_t len, ui return status; } +void ds1992_scratch_copy(uint16_t addr, uint8_t es_reg) +{ + w1_byte_wr(SKIP_ROM); + w1_byte_wr(0x55); // copy scratchpad to memory + w1_byte_wr((addr & 0x00FF)); + w1_byte_wr((addr & 0xFF00) >> 8); + w1_byte_wr(es_reg); + + while(w1_byte_rd() != 0); +} void w1_command( uint8_t command, uint8_t *id ) { diff --git a/avr/1wire.h b/avr/1wire.h index af48d0b..36160b7 100644 --- a/avr/1wire.h +++ b/avr/1wire.h @@ -28,4 +28,6 @@ void w1_command( uint8_t command, uint8_t *id ); void ds1992_read(uint16_t addr, uint8_t* buf, uint8_t len); void ds1992_scratch_write(uint16_t addr, const uint8_t* buf, uint8_t len); uint8_t ds1992_scratch_verify(uint16_t addr, const uint8_t* buf, uint8_t len, uint8_t* es_reg_ptr); +void ds1992_scratch_copy(uint16_t addr, uint8_t es_reg); + #endif diff --git a/avr/main.c b/avr/main.c index 15d98d3..f79853e 100644 --- a/avr/main.c +++ b/avr/main.c @@ -212,6 +212,19 @@ int main(void) goto write_failed; } + result = w1_reset(); + if (result != 0) + { + replyBuffer[0] = 0x03; + error = 1; + goto write_failed; + } + + // commit the write + ds1992_scratch_copy(writepos, es_reg); + + + replyBuffer[0] = 0xFF; // success error = 0; -- cgit v1.2.3