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.PDF4. 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