This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DS1307 RTC INTERFACE WITH TIVA

Other Parts Discussed in Thread: TM4C1294NCPDT

Hello,

         I want to interface DS1307 with  TIVA C LM4C123GH6PM. I write this code but if i am read second,hour,min,year  all have the same value=255,i can,t not understand what is the problem with it.

-darshan

1778.rtc.txt
#include "utils/ustdlib.h"
#include "inc/hw_i2c.h"
#include "driverlib/i2c.h"
#include <string.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "grlib/grlib.h"
#include "utils/cmdline.h"
//#include "utils/uartstdio.h"
#include "fatfs/src/ff.h"
#include "fatfs/src/diskio.h"
#include "drivers/cfal96x64x16.h"
#include "driverlib/timer.h"
#include "driverlib/debug.h"
#include "driverlib/adc.h"
#include "driverlib/pin_map.h"
#include "driverlib/uart.h"
#define    BYTE            unsigned char
#define SLAVE_ADDRESS 0xD0
extern void InitConsole(void);
extern unsigned char dec2bcd(unsigned char val) ;
extern unsigned char bcd2dec(unsigned char val) ;


unsigned long tsec,tmin,thour,tday,tdate,tmonth,tyear;
unsigned char dec2bcd(unsigned char val)
{
	return (((val / 10) << 4) | (val % 10));
  //return ((val/0xA*0x10)+(val%0xA));
}

// convert BCD to binary
unsigned char bcd2dec(unsigned char val)
{
  return (((val & 0xF0) >> 4) * 10) + (val & 0x0F);
  //return ((val/0x10*0xA)+(val%0x10));
}
void InitConsole(void)
{

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //GPIOPinConfigure(GPIO_PA0_U0RX);
    //GPIOPinConfigure(GPIO_PA1_U0TX);

   // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

  //  UARTStdioInit(0);
}

int main()
{
    unsigned long sec=3,min =21,hour = 4,day = 7,date = 20,month = 4,year = 14;
    unsigned char Last_Value = 1;
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    //InitConsole();
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysTickPeriodSet(SysCtlClockGet());
    SysTickEnable();
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    //GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
    I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS , false);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    I2CMasterDataPut(I2C0_MASTER_BASE, 0x00);
    //while(!(I2CSlaveStatus(I2C0_SLAVE_BASE) & I2C_SCSR_RREQ));
    while(I2CMasterBusy(I2C0_MASTER_BASE));
    I2CMasterDataPut(I2C0_MASTER_BASE, dec2bcd(sec));
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE));
    I2CMasterDataPut(I2C0_MASTER_BASE, dec2bcd(min));
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE));
    I2CMasterDataPut(I2C0_MASTER_BASE, dec2bcd(hour));
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE));
    I2CMasterDataPut(I2C0_MASTER_BASE, dec2bcd(day));
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE));
    I2CMasterDataPut(I2C0_MASTER_BASE, dec2bcd(date));
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE));
    I2CMasterDataPut(I2C0_MASTER_BASE, dec2bcd(month));
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE));
    I2CMasterDataPut(I2C0_MASTER_BASE, dec2bcd(year));
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    while(I2CMasterBusy(I2C0_MASTER_BASE));
    while(1)
    {
        I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS , false);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
        I2CMasterDataPut(I2C0_MASTER_BASE, 0x00);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS , true);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        sec = I2CMasterDataGet(I2C0_MASTER_BASE);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        min = I2CMasterDataGet(I2C0_MASTER_BASE);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        hour = I2CMasterDataGet(I2C0_MASTER_BASE);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        day = I2CMasterDataGet(I2C0_MASTER_BASE);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        date = I2CMasterDataGet(I2C0_MASTER_BASE);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        month = I2CMasterDataGet(I2C0_MASTER_BASE);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        year = I2CMasterDataGet(I2C0_MASTER_BASE);
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
        while(I2CMasterBusy(I2C0_MASTER_BASE));
        tsec =  bcd2dec(sec)&0x7f;
        tmin =     bcd2dec(min);
        thour = bcd2dec(hour)&0x3f;
        tday =     bcd2dec(day);
        tdate = bcd2dec(date);
        tmonth = bcd2dec(month);
        tyear = bcd2dec(year);
       /* if(Last_Value != tsec)
        {
            UARTprintf("%02d:%02d:%02d \n%02d %02d/%02d/%02d\n",thour,tmin,tsec,tday,tdate,tmonth,tyear);
            Last_Value = tsec;
            tsec  = 0;
        }*/

    }


}
 

  • Hello,

            I have used 1 k external buffer resister.I guess that  write process is done correctly but reading is not executed correctly.

    -darshan   

  • Hello Darshan

    What interface of TIVA are you using?

    Regards

    Amit

  • Hello amit,

    I want to interface it using i2c.

    Thank you..

    -Darshan

  • Hello Darshan,

    To be sure that write is happening I would ask you to put a scope/LA and see if the Write is working ifne

    1. There is no ADDR or DATA NAK.

    2. When using the condition it would be better to do   while(I2CMasterBusy(I2C0_MASTER_BASE));

        while(!I2CMasterBusy(I2C0_MASTER_BASE));
        while(I2CMasterBusy(I2C0_MASTER_BASE));

    to make sure that the CPU waits for the I2C State Machine to be processing the first request before making the next

    3. Remove the following line I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

    Regards

    Amit

  • Hello darshan bhanushali

    Even I have been facing the same issue, as receiver is returning value 255.

    Can you please suggest me how to resolve this issue ? as we have tried to rectify the issue using same posts but couldn't,

    and may I know what micro you are using, as I have been using TM4C123GXL Launchpad.

    Is it portable to lm4f232h5qd evaluation board ? , please reply me,

    Thanks & Regards

    vijay

  • The return value 255 indicates something got NAKed or that the device is not responding successfully. I can only repeat what Amit said: can you please capture a picture of an oscilloscope or Logic Analyzer probe on the i2c bus.

  • Hello Vijay,

    Can you post the code that you have (as an attachment). The code between TM4C123 and LM4F232 is completely portable.

    Regards

    Amit

  • Hello Vijay,

    Can you set clock and data pin for open drain operation ?

    Here i post one hint for you,which is work for me.

     and please read the datasheet of your controller carefully than you will easily  got the solution.

    // Set GPIO Pins for Open-Drain operation
    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
    GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);

    // Give control to the I2C Module
    GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_DIR_MODE_HW);
    GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_DIR_MODE_HW);

    Regards,

    Darshan Bhanushali.

  • 7536.i2c CODE FOR TM4C123GXL.txt
    #include"tm4c123gh6pm.h"
    #include <stdint.h>
    #include <stdbool.h>
    #include "pin_map.h"
    #include "gpio.h"
    #include "hw_memmap.h"
    #include "hw_types.h"
    #include "sysctl.h"
    #include "i2c.h"
    #define TARGET_IS_BLIZZARD_RB1
    #include "rom.h"
    #include "interrupt.h"
    #include "hw_i2c.h"
    #include "systick.h"
    #define GPIO_PA6_I2C1SCL        0x00001803
    #define GPIO_PA7_I2C1SDA        0x00001C03
    
    unsigned char addr=0x00;
    unsigned char i=0;
    //unsigned char data;
    unsigned char sec,min,hour;
    
    void
    Delay(uint32_t ui32Seconds)
    {
        while(ui32Seconds--)
        {
            while(ROM_SysTickValueGet() > 1000)
            {
            }
    
        }
    }
    
    void Master_Transmit_Receive()
    {
    // Slave address = 0x68
    	ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, false);
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    	Delay(1);
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00);
    	Delay(1);
    //	while(!(ROM_I2CMasterBusy(I2C1_BASE))){};
    	while(ROM_I2CMasterBusy(I2C1_BASE)){};
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00); //SEC
    	Delay(1);
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    	Delay(1);
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    	
    	ROM_I2CMasterDataPut(I2C1_BASE, 0X01);//MIN
    	Delay(1);
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    	Delay(1);
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0X05);//HOUR
    	Delay(1);
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    	Delay(1);
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    
    	while(1)
    	{
    
            ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, true);
            Delay(1);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
            Delay(1);
    //		while(!(ROM_I2CMasterBusy(I2C1_BASE))){}; 
            while(ROM_I2CMasterBusy(I2C1_BASE));
            Delay(1);
    
    
            sec = ROM_I2CMasterDataGet(I2C1_BASE);
            Delay(1);
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
            Delay(1);
            while(ROM_I2CMasterBusy(I2C1_BASE));
            Delay(1);
    
            min = ROM_I2CMasterDataGet(I2C1_BASE);
            Delay(1);
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
            Delay(1);
            while(ROM_I2CMasterBusy(I2C1_BASE));
            Delay(1);
    
            hour = ROM_I2CMasterDataGet(I2C1_BASE);
            Delay(1);
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
            Delay(1);
            while(ROM_I2CMasterBusy(I2C1_BASE));
            Delay(1);
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH);
            Delay(1);
    	}
    }
    
    int main(void)
    {
    
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
    
        ROM_GPIOPinConfigure(GPIO_PA6_I2C1SCL);
        ROM_GPIOPinConfigure(GPIO_PA7_I2C1SDA);
    
        ROM_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
        ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
    
        ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
        ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
    
        ROM_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_DIR_MODE_HW);
        ROM_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_DIR_MODE_HW);
    
        ROM_I2CMasterInitExpClk(I2C1_BASE, ROM_SysCtlClockGet(), false);
    
        Master_Transmit_Receive();
    
    }
    

    Hello Amit & Darshan, here  I attached the code of i2c which I have been using.

    Thanks for replying back.

    Regards

    Vijay 

  • Hello Vijay,

    In the main section you do not need to do the following

    1.

        ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
        ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);

        ROM_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_DIR_MODE_HW);
        ROM_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_DIR_MODE_HW);

    2. The System Clock is configured to be 1.6Mhz. At this system frequency the I2C Baud Rate of 100KHz is not possible. Please use at least 4MHz or above as the system frequency

    In the start the define

    #define TARGET_IS_BLIZZARD_RB1

    has to be placed in the PreDefine section

    Regards

    Amit

  • Amit Ashara said:
    The System Clock is configured to be 1.6Mhz.

    Suspect this results more from misunderstanding than deliberate choice.  Poster may need to spend more (i.e. some) time reviewing Peripheral Driver Library User Guide...  (and multiple, related code examples)

    Attention to detail may need "tweak" too - op's MCU was clearly stated - opening post - yet escaped follow-on poster...

  • Hello cb1,

    I should have been more clear regarding the values of 1.6Mhz. The TPR valid values are from 1-127. The corresponding system frequency would result in the value of 0,8 (dec is 0) which is an illegal value and may be the cause of why the I2C is not working.

    Regards

    Amit

  • Hello amit,

    Thank you very much for the response, but I have been trying for the correct output, from last two days.

    code was attached to the post

    1104.i2c with tm4c123gxl .txt
    #include"tm4c123gh6pm.h"
    #include <stdint.h>
    #include <stdbool.h>
    #include "pin_map.h"
    #include "gpio.h"
    #include "hw_memmap.h"
    #include "hw_types.h"
    #include "sysctl.h"
    #include "i2c.h"
    #include "interrupt.h"
    #include "hw_i2c.h"
    #include "systick.h"
    #define TARGET_IS_BLIZZARD_RB1
    #include "rom.h"
    
    
    #define GPIO_PA6_I2C1SCL        0x00001803
    #define GPIO_PA7_I2C1SDA        0x00001C03
    
    unsigned char sec,min,hour;
    
    void Master_Transmit_Receive()
    {
    
    	ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, false);
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE)){};
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00); //sec
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00);//MIN
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00);//HOUR
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    
    	while(1)
    	{
            ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, false);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    
            ROM_I2CMasterDataPut(I2C1_BASE, 0x00);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
            ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, true);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
            sec = ROM_I2CMasterDataGet(I2C1_BASE);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
    
    
            min = ROM_I2CMasterDataGet(I2C1_BASE);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
    
            hour = ROM_I2CMasterDataGet(I2C1_BASE);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH);
    
    	}
    }
    
    int main(void)
    {
    
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
    
        ROM_GPIOPinConfigure(GPIO_PA6_I2C1SCL);
        ROM_GPIOPinConfigure(GPIO_PA7_I2C1SDA);
    
        ROM_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
        ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
    
        //ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
        //ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
    
        //ROM_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_DIR_MODE_HW);
        //ROM_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_DIR_MODE_HW);
    
        ROM_I2CMasterInitExpClk(I2C1_BASE, ROM_SysCtlClockGet(), false);
    
        Master_Transmit_Receive();
    
    }
    

    1. I am getting loaded with the value of  FF in all the three parameters of hours, mins & seconds, when I am trying to debug.

    2. Also the value is getting loaded with the value 80 and FF are varying.

    I tried to resolve it by giving more sysclock frequency  and

    ROM_I2CMasterInitExpClk(I2C1_BASE, ROM_SysCtlClockGet(), false); change the bit rate to

    true (400kbps) & false (100kbps) with different sys clock frequencies, but result doesn't gets varied.

    How  to configure the clock for more speed like 1Mbps ?

    How to configure the TPR value using correct command?

    At some point of execution we have seen the results of the parameters getting incremented correctly, but not exactly according to Real time clock there was the delay of 4sec for 1 sec (for every 4 seconds one second is being incremented, so please assist us in resolving the problem?

    The resistance values I have been using with DS1307 hardware is 2.1k resistors, hard enough to pull up or do we need to change the resistance values to 1k?

  • Hello Yarlagadda,

    First the queries

    1. For configuring the clock for more speed like 1Mbps, you would need to over-write the TPR value using HWREG macro and access to the I2C_MTPR registe.

    2. The correct command would be (after the ROM_I2CMasterInitExpClk call)

    HWREG(I2C1_BASE+I2C_O_MTPR) = ui32TPR1Mbps

    where ui32TPR1Mbps would be calculated by the equation

    SCL_PERIOD = 2 × (1 + TIMER_PRD) × (SCL_LP + SCL_HP) × CLK_PRD

    Also the System Frequency needs to be 40MHz or more for 1Mbps.

    To debug the issue, if you have a scope plot for both the Write and Read transactions, then it would be of more use.

    Regards

    Amit

  • Hello amit,

    Thanks for various solutions, I tried out with all of them but, unable to update the values of RTC correctly.

    As the values are being updated but the same pattern as I mentioned before

    1. For every 4 sec 1 sec value is being updated ?

    2. Sometimes the variation is between the values 0x80 & 0xFF only.

    inspite of these two there is one more problem to configure it in high speed.

    Please give the solution for the above problem as quickly as possible. as I attached the output I got.

    7802.i2c hs mode.txt
    #include"tm4c123gh6pm.h"
    #include <stdint.h>
    #include <stdbool.h>
    #include "pin_map.h"
    #include "gpio.h"
    #include "hw_memmap.h"
    #include "hw_types.h"
    #include "sysctl.h"
    #include "i2c.h"
    #include "interrupt.h"
    #include "hw_i2c.h"
    #include "systick.h"
    #define TARGET_IS_BLIZZARD_RB1
    #include "rom.h"
    
    #define I2C_O_MTPR              0x0000000C  // I2C Master Timer Period
    #define I2C_HS_PREAMBLE		    0000100
    
    #define GPIO_PA6_I2C1SCL        0x00001803
    #define GPIO_PA7_I2C1SDA        0x00001C03
    #define I2C_MCS_HS 				0x00000010 // High-Speed Enable
    #define I2C_MTPR_HS				0x00000080 // High-Speed Enable
    #define I2C_PP_HS               0x00000001  // High-Speed Capable
    #define I2C_PC_HS               0x00000001  // High-Speed Capable
    
    unsigned char sec,min,hour;
    uint32_t ui32TPR;
    
    void Master_Transmit_Receive()
    {
    	ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, false);
    
    	ROM_I2CMasterSlaveAddrSet(I2C1_BASE, I2C_HS_PREAMBLE, true);
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_HS_MASTER_CODE_SEND);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE)){};
    
    	ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, false);
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE)){};
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00); //sec
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00);//MIN
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    
    	ROM_I2CMasterDataPut(I2C1_BASE, 0x00);//HOUR
    
    	ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    
    	while(ROM_I2CMasterBusy(I2C1_BASE));
    
    	while(1)
    	{
            ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, false);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    
            ROM_I2CMasterDataPut(I2C1_BASE, 0x00);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
            ROM_I2CMasterSlaveAddrSet(I2C1_BASE, 0x68, true);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
            sec = ROM_I2CMasterDataGet(I2C1_BASE);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
    
    
            min = ROM_I2CMasterDataGet(I2C1_BASE);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
    
            hour = ROM_I2CMasterDataGet(I2C1_BASE);
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    
            while(ROM_I2CMasterBusy(I2C1_BASE));
    
            ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_FIFO_BURST_RECEIVE_FINISH);
    
    	}
    }
    
    int main(void)
    {
    
        //ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
        ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
        ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
    
        ROM_GPIOPinConfigure(GPIO_PA6_I2C1SCL);
        ROM_GPIOPinConfigure(GPIO_PA7_I2C1SDA);
    
        ROM_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
        ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
    
        //ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
        //ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
    
        //ROM_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_DIR_MODE_HW);
        //ROM_GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_DIR_MODE_HW);
    
        ROM_I2CMasterInitExpClk(I2C1_BASE, ROM_SysCtlClockGet(), false);
    
        //ui32TPR = 0x01;
        //HWREG(I2C1_BASE+I2C_O_MTPR) = ui32TPR;
    
    
        Master_Transmit_Receive();
    
    }
    

    Thanks & Regards

    Vijay 

     

     

     

  • Hello Vijay,

    Before jumping the wagon on to HS, it is important that we get the Standard Mode working. Can you send a snapshot of the waveform when the write is done to the Slave RTC device and then first read?

    Also a schematic of how you have connected the TM4C device to the Slave RTC device would be useful to see if we are not missing something on the connections

    Regards

    Amit

  • Hi,

    Thank you for your reply,I have connected DS1307

    1. Vbat to 3.3V dc power supply,

    2. X1 and X2 to 32KHZ crystal,

    3. SCL and SDA pins of DS1307 to PA6 and PA7 pins of TM4C with 8.2K pull up resisters.

    and with proper ground connections.  

    When I connect 5V to VCC pin of DS1307 without VBAT voltage, getting 3sec of delay as I have already mentioned, but now with the above connection, getting only 255.

    Please check and reply.

    Regards,

    Vijay

     

  • Hello Vijay

    Thanks for the explanation, but sometimes the schematics put a better picture.

    Also I requested for the scope snapshot. That would be useful for me to relate the code to the transactions. Without it we can run in circles.

    Regards

    Amit

  • Hello Darshan,
    I am also facing the same problem. Have you solved yours?
    If yes can you please help me with it!!
    -Nikhil
  • Dear Amit,
    I am facing a similar problem. I am successful in initialising and interfacing the ds1307 with with TM4C1294NCPDT. I can see value on the serial monitor. I can see the correct hour, seconds,date and year but the day , minute and month displayed are wrong. Besides, the minutes are not updating.What should I do?
    Regards,
    Keyshav
  • Very Very sorry nikhil

    Now i am not working with technical field. But i had successfully interface rtc with it 2 year ago.So study  thoroughly viva and rtc than use defiantly interface it.

    All the best.

    Regards

    Darshan 

  • Hello Darshan,
    My RTC is working fine. But it is not updating the minutes once the seconds cross 60. What should I do?
    Regards,
    Keyshav