2 Replies Latest reply on Sep 17, 2019 12:25 AM by MoTa_728816

    ds1307 rtc reading random values

    NaAd_4382031

      hello.

      I'm working on an rtc based project although this is my first time of using it. the external rtc I interfaced with psoc4 is reading random values.  can someone pls tell me what could be the problem. Attached below is the code.

        • 1. Re: ds1307 rtc reading random values
          BragadeeshV_41

          Hi NaAd_4382031,

           

          Please refer to the code example CE222306 – PSoC 4 I2C Master that shows the implementation of I2C low level Apis.

          https://www.cypress.com/documentation/code-examples/ce222306-psoc-4-i2c-communication-serial-comunication-block-scb

           

          Also check the status of I2C_I2CMasterWriteByte(0x00, timeOut);. Proceed further only if status returns I2C_I2C_MSTR_NO_ERROR.

          Also please probe the I2C lines and check if there is any issues in the data sent from the master.

           

          Regards,

          Bragadeesh

          • 2. Re: ds1307 rtc reading random values
            MoTa_728816

            Hi,

             

            I briefly read your source.

            According to the datasheet of DS1307

            DS1307_REGS.JPG

             

            The data read from the RTC module seems to be hex data and you are trying to write them as a string.

             

            How about changing your program as below

            (1) include "stdio.h" after "project.h" to use sprintf()

            #include "project.h"

            #include "stdio.h"

             

            (2) add work char after uint8 RTC_TIME[ARRAY_SIZE] ;

            uint8 RTC_TIME [ARRAY_SIZE} ;

            char str[16] ; // HH:MM:SS\r\n+NULL = 12bytes (16 is with some extra)

             

            (3) comment out line 63

            // UART_SpiUartWriteTxData((uint32)RTC_TIME) ;

             

            (4)  modify lien 69

            > UART_SpiUartPutArray(RTC_TIME, ARRAY_SIZE) ;

            to

            sprintf(str, "%02X/%02X/%02X ", RTC_TIME[5], RTC_TIME[4], RTC_TIME[3]) ;

            UART_UartPutString(str) ;

            sprintf(str, "%02:%02:%02\r\n", RTC_TIME[2], RTC_TIME[1], RTC_TIME[0]) ;

            UART_UartPutString(str) ;

             

            moto