Mercurial > ~darius > hgwebdir.cgi > avr
diff testavr.c @ 60:50fca9562310
Add support for reading/writing to a DS1307 over TWI/IIC.
Note that iic_read() appears to have a bug where it stops 1 byte earlier than
expected, work around it for now by adding 1 in the gettod() function.
tempctrl.c now prints the TOD as read from the RTC for each line.
author | darius@Inchoate |
---|---|
date | Thu, 30 Oct 2008 11:53:32 +1030 |
parents | 09f8d879afb9 |
children | 4d914a1fd487 |
line wrap: on
line diff
--- a/testavr.c Thu Oct 30 11:44:52 2008 +1030 +++ b/testavr.c Thu Oct 30 11:53:32 2008 +1030 @@ -42,6 +42,7 @@ #include "usb.h" #endif #include "tempctrl.h" +#include "ds1307.h" /* * Mirror of the MCUCSR register, taken early during startup. @@ -114,9 +115,15 @@ /* Set up the one wire stuff */ OWInit(); + /* Setup IIC */ + ds1307_init(); + /* Init UART */ cons_init(); + /* Init temperature control stuff */ + tempctrl_init(); + printf_P(PSTR("\r\n\r\n===============\r\n" "Inited!\r\n\r\n")); @@ -135,8 +142,6 @@ if ((mcucsr & _BV(JTRF)) == _BV(JTRF)) printf_P(PSTR("JTAG reset\r\n")); - tempctrl_init(); - /* Ready to go! */ sei(); @@ -204,10 +209,12 @@ "we ROMID adr val Write data into a DS2502 PROM (adr & val in hex)\r\n" "rr ROMID Read DS2502 PROM\r\n" "zz Reset MCU\r\n" + "gc Get time of day\r\n" + "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n" #ifdef WITHUSB "us Generate USB data\r\n" #endif - "tc ... Temperature control related (tc help for more)\r\n")); + "tc ... Temperature control related (tc help for more)\r\n" return; } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) { @@ -549,9 +556,18 @@ } else if (!strncasecmp_P((char *)cmd.buf, PSTR("us"), 2)) { usb_gendata(); #endif + } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) { + ds1307_printtime(PSTR(""), PSTR("\r\n")); + } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) { + if (cmd.len < 17) { + printf_P(PSTR("Command not long enough\r\n")); + } else { + if (ds1307_settod(cmd.buf + 3) != 1) + printf_P(PSTR("Unable to set time of day\r\n")); + } } else { printf_P(PSTR("Unknown command, help for a list\r\n")); } } - +