External realtime clock - midibox extension
#1
Posted 05 September 2007 - 12:45
I'm thinking of a Hour/Min/Sec clock, So an application could "know" what time is it,
(then trigger an action at a certain time)
I think it could be very interesting, but dont know yet how it could be done ;)
#2
Posted 05 September 2007 - 17:29
I know about the PCF8583 or the DS1307, a real-time clock and calendar with IIC interface. There are plenty of different chips and also relative code for PIC to use them. Just look for them!
RAZ
#7
Posted 06 September 2007 - 11:20
Quote
I dont have a very precise idea, but i like to experiment, learn about ic2, and use the midibox for other purpose than pure midi application (like robotic or domotic). :)
#8
Posted 06 September 2007 - 12:00
I would really like to see what different you did with MB platform.
Quote
That is funny, but same time, reminds me that we are distancing from the people and getting better with machines.
#9
Posted 06 September 2007 - 14:23
You could make a SID alarm clock :)
#11
Posted 04 October 2007 - 13:30
PCF8583 Real Time Clock Mini Board
DS1307 MCU Add-On Board DS1307 Real Time Clock
#12
Posted 23 October 2007 - 19:38
I bought a board like this one to experiment IIC : http://www.futurlec....ni_DS1307.shtml
http://www.rev-ed.co...docs/DS1307.pdf
so i connected the board to the core without problem,
and initialised the IIC like this :
void Init(void) __wparam
{
MIOS_IIC_Stop(); // init IIC interface
}
then, looking at the speakjet code i did this :
unsigned char IIC_TransmitStart(unsigned char _slave) __wparam
{
unsigned char retry_ctr;
// start IIC access
MIOS_IIC_Start();
// send address
retry_ctr = 0;
while( !MIOS_IIC_ByteSend( _slave ) ) {
// slave has sent a NAK - retry 255 times
MIOS_IIC_Stop();
if( ++retry_ctr == 255 )
return 0;
MIOS_IIC_Start();
}
return 1;
}and this : (slave value is 0xD0)
void DISPLAY_Init(void) __wparam
{
MIOS_LCD_Clear();
if(!IIC_TransmitStart(slave) ){
MIOS_LCD_CursorSet(0x00);
MIOS_LCD_PrintCString("IIC Transmit error !");
}else{
MIOS_LCD_CursorSet(0x00);
MIOS_LCD_PrintCString("IIC Transmit OK");
}
}
at this point, everything seems ok, i have "IIC Transmit OK" :)
then, i try to read some values so i did :

void GET_TIME(void){
MIOS_IIC_Start(); // start IIC
MIOS_IIC_ByteSend(slave); // send device address -
// set bit #0 to notify a read!!!
// don't continue if IIC device not available
if( MIOS_BOX_STAT.BS_AVAILABLE){
b0 = MIOS_IIC_ByteReceive();
MIOS_IIC_AckSend(); // send acknowledge
b1 = MIOS_IIC_ByteReceive();
}
MIOS_IIC_NakSend(); // send disacknowledge!!!
MIOS_IIC_Stop(); // stop IIC
MIOS_LCD_CursorSet(0x40);
MIOS_LCD_PrintHex2(b0);
MIOS_LCD_PrintCString(":");
MIOS_LCD_PrintHex2(b1);
}but all i read, whenever i call this function is just some random values, instead of seconds :-\
maybe this project is a little too complicated for me,
to be honest, i dont know exactly how it's supposed to work,
but i guess i'm must not be that far from the goal, so i hope some people here can explain me what i did wrong, or did not :)
thanks for reading !
#13
Posted 23 October 2007 - 20:26

I know slave adress should be 0xD1 (1101000+1) (the 1 is for "read" mode)
I did enable clock stretching with MIOS_IIC_CtrlSet(0x01);
but my received bytes are still random... :-\
#14
Posted 23 October 2007 - 21:40
but i have one more question that maybe some of you could answer.
The DS1307 doc (http://www.rev-ed.co...docs/DS1307.pdf) say :
Quote
The address map for the RTC and RAM registers of the DS1307 is shown in Figure 2. The real time
clock registers are located in address locations 00h to 07h. The RAM registers are located in address
locations 08h to 3Fh.
So, i'm only interested on the "real time clock registers" at the moment, so, all i need to get is the 8 first bytes after this
MIOS_IIC_Start(); // start IIC MIOS_IIC_ByteSend(slave); // send device address
is that right ?
#15
Posted 23 October 2007 - 22:16
But the datasheet says, that there is an address pointer which will be incremented on each read operation. It isn't explicitely mentioned, but I would expect that you need to reset the pointer by hand when you want to read from zero.
So, the code should look somehow like this (quick hack, errors can be expected)
MIOS_IIC_Start(); MIOS_IIC_ByteSend(0xd0); // slave address, write operation MIOS_IIC_ByteSend(0x00); // set address pointer to 0 MIOS_IIC_Stop(); MIOS_IIC_Start(); MIOS_IIC_ByteSend(0xd1); // slave address, read operation b0 = MIOS_IIC_ByteReceive(); MIOS_IIC_AckSend(); b1 = MIOS_IIC_ByteReceive(); MIOS_IIC_NakSend(); MIOS_IIC_Stop();
once this sequence is working, you can add all the robustness stuff, like check for BS_AVAILABLE, etc
Best Regards, Thorsten.
#16
Posted 24 October 2007 - 15:35
your example help me a lot (to understand how it's supposed to work), today i found this
http://www.techdesig...1307_void_a.htm
Quote
However, it is, basically.
So when reading from the DS1307 (=Slave) and seen by the PIC's point of view (=Master), we have to:
1) Send a START, write the device address (0xd0) (last bit is 0 for write), wait for ACK.
2) Write the word address (sets the first register to read from, which is 0x00 here), wait for ACK.
3) Send a REPEATED START, write the device address again (0xd1) (last bit is 1 for read), wait for ACK.
4) Read the first byte, wait for ACK.
5) Repeat step 4) for next bytes.
6) Read the last byte, no wait for ACK, send STOP.
We have to repeat this whole cycle each time we start reading the DS1307 registers, otherwise they will be incremented automatically, and not set to zero.
This is basically what you wrote yesterday (minus the first "STOP")
I also found some code supposed to work :
http://jambonbill.fr...LOCK/main.c.txt
http://jambonbill.fr...CK/ds1307.c.txt
I will continue to experiment this evening ;)
#18
Posted 24 October 2007 - 21:02
Best Regards, Thorsten.
#19
Posted 05 November 2007 - 23:38
if someone is interested, let me know, so i do a user project page for this :)
#20
Posted 06 November 2007 - 10:21
Quote
Great! :)
Please, do it. Thank you Bill.



Help
















