External realtime clock - midibox extension

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 :wink:

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

http://www.futurlec.com/Mini_PCF8583.shtml

http://www.futurlec.com/Mini_DS1307.shtml

thanks !!!

those lil boards looks great  ;D

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

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

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). :slight_smile:

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.

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.

I dunno, I always think about the programmers when it does that :wink:

You could make a SID alarm clock :slight_smile:

That would be so cool.  :smiley:

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

Dear forum,

I bought a board like this one to experiment IIC : http://www.futurlec.com/Mini_DS1307.shtml

http://www.rev-ed.co.uk/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” :slight_smile: 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 :slight_smile:

thanks for reading !

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…  :-

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.uk/docs/DS1307.pdf) say :

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 ?

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();
[/code]









once this sequence is working, you can add all the robustness stuff, like check for BS\_AVAILABLE, etc







Best Regards, Thorsten.

Thank you Thorsten,

your example help me a lot (to understand how it’s supposed to work), today i found this

http://www.techdesign.be/projects/routines/ds1307_void_a.htm

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.free.fr/midibox-kb/MBHP-CLOCK/main.c.txt

http://jambonbill.free.fr/midibox-kb/MBHP-CLOCK/ds1307.c.txt

I will continue to experiment this evening :wink:

now it works  ;D more details soon !

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.

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

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

Great!  :slight_smile:

Please, do it. Thank you Bill.