Author Topic: external RTC with uTaskerV1.3.0_M5223X_SP6  (Read 9140 times)

Offline evgenik

  • Newbie
  • *
  • Posts: 18
    • View Profile
external RTC with uTaskerV1.3.0_M5223X_SP6
« on: March 24, 2008, 05:06:00 PM »
Hi Mark.
I work with external RTC DS1338(very similar to your RTC) with Freescale M5223 micro and have problems with read(save data) and write:
In SP6 have functions: fnConfigureRTC - for save time to RTC registers;
       fnWrite(IICPortID, (unsigned char*)ucGetTime, sizeof(ucGetTime)); - use for save data (ucGetTime array)to external RTC or or fnSaveTime(); but after saving i don't receive from RTC right data.
       fnRead(IICPortID, (unsigned char *)&ucSlave, 7); - use for read data from external RTC to ucSlave array.
In oscilloscope i can view data in read mode, but i can't view it in array ucSlave. Where saved data is received from external RTC (in array or registers) ? In array ucSlave :const unsigned char ucSlave[] = {7, (ADDRTC_READ), OWN_TASK} (in your example) i haven't RTC data (here only these 3 parameters). When i want update time to external RTC fnWrite don't send data. May be have any order with read and write to IIC(RTC)?
Thanks.
Evgeni.

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3236
    • View Profile
    • uTasker
Re: external RTC with uTaskerV1.3.0_M5223X_SP6
« Reply #1 on: March 24, 2008, 08:31:31 PM »
Hi Evgeni

I don't understand exactly the problem at the moment, but here are some initial notes.

1. The DS1338 does seem to be compatible with the DS1307, which is supported in the demo code. It also has the same I2C address.

2. The routine fnConfigureRTC() is used together with the internal RTC and so doesn't influence an external one - it should however be possible to synchronise the time read from and external RTC to the internal one, after converting the format to suit.

3. The RTC demo is briefly discussed in the document: http://www.utasker.com/docs/uTasker/uTaskerIIC_002.PDF

4. If you use the uTasker simulator you can step through the code to see what is expected from a correctly operating RTC and then compare it to your target in case something doesn't work the same. (Activate the define TEST_DS1307 in application.c). #define IIC_INTERFACE also needs to be active in config.h.

5. Check that your circuitry is correct. You will need pull-up lines on the I2C bus for it to work properly (1.5k is recommended).

6. The first thing that needs to be checked is that the RTC is correctly operating - the crystal must be operating and the power supply correct - then it should answer.

7. The first thing that the code does is to configure the RTC:
fnWrite(IICPortID, (unsigned char *)ucStartRTC, sizeof(ucStartRTC));
This enables the device and also generates a 1Hz signal on its output SQW. This needs a pull-up resistor to be measured, and a correct signal indicates that the RTC has indeed been correctly configured.

8. After the configuration fnGetRTCTime() is used to retrieve the present data and time. This sends first the internal register address to be read (0) and starts a read of 7 bytes form this position.

9. When the 7 bytes have been received by the I2C driver, the task fnApplication() will be woken. The I2C driver queue is checked for data - fnMsgs(IICPortID) - and extracts the 7 bytes into ucInputMessage using fnRead(IICPortID, ucInputMessage, 7);
If it is seen that the MSB of the first address is set it means that this is the first time the RTC has been used. In this case it sets a time of 0:0:0, which also enables the oscillator, from which point the RTC is fully operating.


At the moment I don't understand which part is not working correctly for you.
Can you explain what is operating correctly and which step is no?
Do you think that it is a hardware problem or a software problem?

Regards

Mark

Offline Thomas

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: external RTC with uTaskerV1.3.0_M5223X_SP6
« Reply #2 on: March 25, 2008, 02:55:23 PM »
Just want to say that I also use the DS1338, though on a SAM7X board, and it works fine with Mark's code without modifications.

Offline evgenik

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: external RTC with uTaskerV1.3.0_M5223X_SP6
« Reply #3 on: March 26, 2008, 10:00:05 AM »
Hi Mark.

My mistake was that I did not send the 'Write and address' before a 'Read, address and data': therefore data were not received.
Example in fnGetRTCTime(void).

Thank you.
Evgeni.