Table of Contents
MB RTC
I started doing the MBClock for no reason but for fun, but i think it can lead to interesting usage, such as domotic.
First, i used a DS1307 I2C Clock
well, more exactly, this dev board : (USD $6.90)
http://www.futurlec.com/Mini_DS1307.shtml
This board hold a battery back-up, enabling the time to be maintained even with power disconnected from the board. The DS1307 IC stores time values in separate registers, for years, month, day, hour, minutes and seconds. I suggest to use this board, as it's cheap, it will save you time on building, and debuging :)
Connection to core
Well, that's pretty easy : connect Gnd,Vcc,Sc,Sd to Core J4. (instead of bankstick)
I did not add a pull up resistor between Vcc and Sc (well, in fact i did, but i didnt notice any difference)
The C Program
void GET_TIME(void){ MIOS_IIC_Start(); MIOS_IIC_ByteSend(0xd0); // slave address, WRITE MIOS_IIC_ByteSend(0x00); // set address pointer to 0 MIOS_IIC_Stop();//??? MIOS_IIC_Start(); // start IIC MIOS_IIC_ByteSend(0xD1); // send address - READ b0 = MIOS_IIC_ByteReceive(); // read byte MIOS_IIC_AckSend(); // send acknowledge b1 = MIOS_IIC_ByteReceive(); // read byte MIOS_IIC_AckSend(); // send acknowledge b2 = MIOS_IIC_ByteReceive(); // read byte MIOS_IIC_AckSend(); // send acknowledge b3 = MIOS_IIC_ByteReceive(); // read byte MIOS_IIC_AckSend(); // send acknowledge b4 = MIOS_IIC_ByteReceive(); // read byte MIOS_IIC_AckSend(); // send acknowledge b5 = MIOS_IIC_ByteReceive(); // read byte MIOS_IIC_AckSend(); // send acknowledge b6 = MIOS_IIC_ByteReceive(); // read byte MIOS_IIC_NakSend(); // send disacknowledge!!! (end the read) MIOS_IIC_Stop(); // stop IIC }
Demo
Just for fun
I have added a 7Seg led display to show the time in that format “HH:MM:SS:ms”
To keep it simple and documented, i used the Midimon MTC Extension as is.