MIDIbox Forum: External realtime clock - midibox extension - MIDIbox Forum

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

External realtime clock - midibox extension Rate Topic: -----

#1 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 05 September 2007 - 12:45

Does anyone have any suggestion, to connect an external "clock", to the core ?
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 User is offline   ris8_allo_zen0 

  • MIDIbox Addict
  • PipPip
  • Group: Programmer
  • Posts: 169
  • Joined: 23-August 06
  • LocationItaly

Posted 05 September 2007 - 17:29

Hi bill,
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

#3 User is offline   sneakthief 

  • MIDIbox Addict
  • PipPip
  • Group: Programmer
  • Posts: 151
  • Joined: 24-January 06
  • LocationBerlin

Posted 06 September 2007 - 10:00

http://www.futurlec....i_PCF8583.shtml
http://www.futurlec....ni_DS1307.shtml

#4 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 06 September 2007 - 10:34

thanks !!!!
those lil boards looks great  ;D
Posted Image

#5 User is offline   Sasha 

  • MIDIbox Guru
  • PipPipPipPip
  • Group: Members
  • Posts: 1,941
  • Joined: 20-March 05
  • LocationBelgrade, Serbia

Posted 06 September 2007 - 10:40

Hey bill, can you tell us something more about your idea?

#6 User is offline   stryd_one 

  • MIDIbox Guru
  • PipPipPipPip
  • Group: Frequent Writer
  • Posts: 8,850
  • Joined: 25-February 03
  • LocationMelbourne, Victoria, Australia

Posted 06 September 2007 - 11:12

I have some FX machines that wish me a happy birthday :)

#7 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 06 September 2007 - 11:20

Quote

Hey bill, can you tell us something more about your idea?


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 User is offline   Sasha 

  • MIDIbox Guru
  • PipPipPipPip
  • Group: Members
  • Posts: 1,941
  • Joined: 20-March 05
  • LocationBelgrade, Serbia

Posted 06 September 2007 - 12:00

Cool. I have an idea of using midibox for some robotic purposes but as I`m not programmer I can only use MB apps as it is without any customization.
I would really like to see what different you did with MB platform.

Quote

I have some FX machines that wish me a happy birthday Smiley

That is funny, but same time, reminds me that we are distancing from the people and getting better with machines.

#9 User is offline   stryd_one 

  • MIDIbox Guru
  • PipPipPipPip
  • Group: Frequent Writer
  • Posts: 8,850
  • Joined: 25-February 03
  • LocationMelbourne, Victoria, Australia

Posted 06 September 2007 - 14:23

I dunno, I always think about the programmers when it does that ;)

You could make a SID alarm clock :)

#10 User is offline   Sasha 

  • MIDIbox Guru
  • PipPipPipPip
  • Group: Members
  • Posts: 1,941
  • Joined: 20-March 05
  • LocationBelgrade, Serbia

Posted 06 September 2007 - 14:42

That would be so cool.  :D

#11 User is offline   stryd_one 

  • MIDIbox Guru
  • PipPipPipPip
  • Group: Frequent Writer
  • Posts: 8,850
  • Joined: 25-February 03
  • LocationMelbourne, Victoria, Australia

Posted 04 October 2007 - 13:30

Just saw these on ebay...bit more expensive though! Thought I'd post them in case futurlec runs out or something.

PCF8583 Real Time Clock Mini Board
DS1307 MCU Add-On Board DS1307 Real Time Clock

#12 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 23 October 2007 - 19:38

Dear forum,
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 :
Posted Image

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 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 23 October 2007 - 20:26

Posted Image
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 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 23 October 2007 - 21:40

I'm sorry to ask again for help, and to look like an asshole,
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

RTC AND RAM ADDRESS MAP
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 User is offline   TK. 

  • MIDIbox Guru
  • View gallery
  • Group: Administrators
  • Posts: 11,146
  • Joined: 01-January 01
  • LocationGermany

Posted 23 October 2007 - 22:16

The code looks correct.

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 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 24 October 2007 - 15:35

Thank you Thorsten,
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

The DS1307 datasheet is quite confusing because the read routine seems not to be the same as with an i²c EEPROM.
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 ;)



#17 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 24 October 2007 - 21:01

now it works  ;D more details soon !

#18 User is offline   TK. 

  • MIDIbox Guru
  • View gallery
  • Group: Administrators
  • Posts: 11,146
  • Joined: 01-January 01
  • LocationGermany

Posted 24 October 2007 - 21:02

According to the IIC spec, it is allowed to omit the STOP so long the same device is accessed again, but I felt saver to show you an example with stop/start, as I know that e.g. the IIC slave of PIC16F88 cannot handle the "restart" condition properly

Best Regards, Thorsten.


#19 User is offline   bill 

  • MIDIbox Tweaker
  • PipPipPip
  • Group: Programmer
  • Posts: 365
  • Joined: 07-June 04
  • LocationBulgaria - Sofia

Posted 05 November 2007 - 23:38


if someone is interested, let me know, so i do a user project page for this :)

#20 User is offline   Sasha 

  • MIDIbox Guru
  • PipPipPipPip
  • Group: Members
  • Posts: 1,941
  • Joined: 20-March 05
  • LocationBelgrade, Serbia

Posted 06 November 2007 - 10:21

Quote

if someone is interested, let me know, so i do a user project page for this Smiley

Great!  :)

Please, do it. Thank you Bill.

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users