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 EXTERNAL RTC WITH TIVA

Other Parts Discussed in Thread: TM4C123GH6PM

Hello,

           I want to interface ds1307 external rtc with tiva-c tm4c123gh6pm.i have send my code,but in the ccs it show me master is alway in busy state,i don't understand the problem with it.What can i do?

I have use 1k external pull up resister with both data and clk line. 

3201.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 0x68
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/0xA*0x10)+(val%0xA));
}

// convert BCD to binary
unsigned char bcd2dec(unsigned char val)
{
  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 =10,hour = 5,day = 4,date = 17,month = 4,year = 14;
    unsigned char Last_Value = 1;
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
    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);
    I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS , false);
    I2CMasterDataPut(I2C0_MASTER_BASE, 0);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
    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);
       

    }


}

-darshan