Hi,
I am trying to interface DS1307 with TM4C1294(connected launchpad). I got it to work in TM4C123 but i am clueless why is it not working in Connected Launchpad. Please help me. The data I'm getting is sometimes jumbled continuously and sometimes only 00:00 is read.
unsigned int sec=3,min=59,tsec=6,tmin=10; #define SLAVE_ADDRESS 0x68 void SRAMRead(void); void SRAMWrite(int a,int b); void initIO(); void ConfigureUART(void); unsigned char dec2bcd(unsigned char val) ; unsigned char bcd2dec(unsigned char val) ; uint32_t ui32SysClkFreq, clockget; //***************************************************************************** // // main() // //***************************************************************************** int main(void) { unsigned char Last_Value=1; ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); clockget=SysCtlClockGet(); SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); GPIOPinConfigure(GPIO_PB3_I2C0SDA); GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); GPIOPinConfigure(GPIO_PB2_I2C0SCL); GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); I2CMasterInitExpClk(I2C0_BASE, ui32SysClkFreq, false); ConfigureUART(); // SRAMRead(); I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS , false); I2CMasterDataPut(I2C0_BASE, 0); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START); while(I2CMasterBusy(I2C0_BASE)); I2CMasterDataPut(I2C0_BASE, dec2bcd(sec)); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT); while(I2CMasterBusy(I2C0_BASE)); I2CMasterDataPut(I2C0_BASE, dec2bcd(min)); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while(I2CMasterBusy(I2C0_BASE)); while(1) { I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS , false); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START); I2CMasterDataPut(I2C0_BASE, 0x00); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH); while(I2CMasterBusy(I2C0_BASE)); I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS , true); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START); while(I2CMasterBusy(I2C0_BASE)); sec = I2CMasterDataGet(I2C0_BASE); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT); while(I2CMasterBusy(I2C0_BASE)); min = I2CMasterDataGet(I2C0_BASE); I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH); while(I2CMasterBusy(I2C0_BASE)); // SRAMWrite(sec,min); tsec = bcd2dec(sec)&0x7f; tmin = bcd2dec(min); if(Last_Value != tsec) { UARTprintf("%02d:%02d\n",tsec,tmin); Last_Value = tsec; tsec = 0; } } } void ConfigureUART(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // UARTConfigSetExpClk(UART0_BASE, ui32SysClkFreq, 115200, // (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTStdioConfig(0, 115200, ui32SysClkFreq); IntMasterEnable(); }