Jump to content

External realtime clock - midibox extension


bill

Recommended Posts

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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...

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" :) then, i try to read some values so i did : DS1307-registers.gif
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 !

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...