comparison 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
comparison
equal deleted inserted replaced
59:c72cf25881fe 60:50fca9562310
40 #include "1wire.h" 40 #include "1wire.h"
41 #ifdef WITHUSB 41 #ifdef WITHUSB
42 #include "usb.h" 42 #include "usb.h"
43 #endif 43 #endif
44 #include "tempctrl.h" 44 #include "tempctrl.h"
45 #include "ds1307.h"
45 46
46 /* 47 /*
47 * Mirror of the MCUCSR register, taken early during startup. 48 * Mirror of the MCUCSR register, taken early during startup.
48 */ 49 */
49 uint8_t mcucsr __attribute__((section(".noinit"))); 50 uint8_t mcucsr __attribute__((section(".noinit")));
112 #endif 113 #endif
113 114
114 /* Set up the one wire stuff */ 115 /* Set up the one wire stuff */
115 OWInit(); 116 OWInit();
116 117
118 /* Setup IIC */
119 ds1307_init();
120
117 /* Init UART */ 121 /* Init UART */
118 cons_init(); 122 cons_init();
119 123
124 /* Init temperature control stuff */
125 tempctrl_init();
126
120 printf_P(PSTR("\r\n\r\n===============\r\n" 127 printf_P(PSTR("\r\n\r\n===============\r\n"
121 "Inited!\r\n\r\n")); 128 "Inited!\r\n\r\n"));
122 129
123 if ((mcucsr & _BV(PORF)) == _BV(PORF)) 130 if ((mcucsr & _BV(PORF)) == _BV(PORF))
124 printf_P(PSTR("Power on reset\r\n")); 131 printf_P(PSTR("Power on reset\r\n"));
133 printf_P(PSTR("Watchdog reset\r\n")); 140 printf_P(PSTR("Watchdog reset\r\n"));
134 141
135 if ((mcucsr & _BV(JTRF)) == _BV(JTRF)) 142 if ((mcucsr & _BV(JTRF)) == _BV(JTRF))
136 printf_P(PSTR("JTAG reset\r\n")); 143 printf_P(PSTR("JTAG reset\r\n"));
137 144
138 tempctrl_init();
139
140 /* Ready to go! */ 145 /* Ready to go! */
141 sei(); 146 sei();
142 147
143 /* 148 /*
144 * Enable the watchdog with the largest prescaler. Will cause a 149 * Enable the watchdog with the largest prescaler. Will cause a
202 "dd port [val] Read/write DDR for a port (val in hex)\r\n" 207 "dd port [val] Read/write DDR for a port (val in hex)\r\n"
203 "rt ROMID Read DS2502 status page\r\n" 208 "rt ROMID Read DS2502 status page\r\n"
204 "we ROMID adr val Write data into a DS2502 PROM (adr & val in hex)\r\n" 209 "we ROMID adr val Write data into a DS2502 PROM (adr & val in hex)\r\n"
205 "rr ROMID Read DS2502 PROM\r\n" 210 "rr ROMID Read DS2502 PROM\r\n"
206 "zz Reset MCU\r\n" 211 "zz Reset MCU\r\n"
212 "gc Get time of day\r\n"
213 "sc time Set time of day (time is YYYY/MM/DD HH:MM:SS)\r\n"
207 #ifdef WITHUSB 214 #ifdef WITHUSB
208 "us Generate USB data\r\n" 215 "us Generate USB data\r\n"
209 #endif 216 #endif
210 "tc ... Temperature control related (tc help for more)\r\n")); 217 "tc ... Temperature control related (tc help for more)\r\n"
211 218
212 return; 219 return;
213 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) { 220 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("zz"), 2)) {
214 cli(); 221 cli();
215 wdt_enable(WDTO_15MS); 222 wdt_enable(WDTO_15MS);
547 tempctrl_cmd((char *)cmd.buf); 554 tempctrl_cmd((char *)cmd.buf);
548 #ifdef WITHUSB 555 #ifdef WITHUSB
549 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("us"), 2)) { 556 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("us"), 2)) {
550 usb_gendata(); 557 usb_gendata();
551 #endif 558 #endif
559 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("gc"), 2)) {
560 ds1307_printtime(PSTR(""), PSTR("\r\n"));
561 } else if (!strncasecmp_P((char *)cmd.buf, PSTR("sc"), 2)) {
562 if (cmd.len < 17) {
563 printf_P(PSTR("Command not long enough\r\n"));
564 } else {
565 if (ds1307_settod(cmd.buf + 3) != 1)
566 printf_P(PSTR("Unable to set time of day\r\n"));
567 }
552 } else { 568 } else {
553 printf_P(PSTR("Unknown command, help for a list\r\n")); 569 printf_P(PSTR("Unknown command, help for a list\r\n"));
554 } 570 }
555 } 571 }
556 572
557 573