I'm using TM4C1294, Tivaware 2.1.1.71. I'm trying to read from DS1307 but i only receive value 0x00 from all registers. Here is my code, please help me
I'm sorry if my English is not so good and thanks for your help.
void BasicConfig()
{
/*
* Sets the clocking to run at 120MHz from the PLL.
*/
SysClock = SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320), 120000000);
}
void UARTConfig()
{
/*
* Enable GPIO port A which is used for UART0 pins.
*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
/*
* Configure the pin muxing for UART0 functions on port A0 and A1.
* This step is not necessary if your part does not support pin muxing.
*/
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
/*
* Enable UART0 so that we can configure the clock.
*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
/*
* Use the internal 16MHz oscillator as the UART clock source.
*/
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
/*
* Select the alternate (UART) function for these pins.
*/
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
/*
* Initializes the UART for console I/O.
*/
UARTStdioConfig(0, 115200, 16000000);
}
void I2CConfig()
{
/*
* Enables I2C7 peripheral.
*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C7);
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C7);
/*
* Enables GPIO port D to use with I2C7 module.
*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
/*
* Select the I2C function for these pins. This function will also
* configure the GPIO pins pins for I2C operation, setting them to
* open-drain operation with weak pull-ups.
*/
GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);
GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
/*
* Configure the pin muxing for I2C7 functions on port D0 and D1.
*/
GPIOPinConfigure(GPIO_PD0_I2C7SCL);
GPIOPinConfigure(GPIO_PD1_I2C7SDA);
/*
* Enables the I2C Master block.
*/
// I2CMasterEnable(I2C7_BASE);
/*
* Initializes the I2C Master block. The master block is set up
* to transfer data at standard-mode(100 Kbps)
*/
I2CMasterInitExpClk(I2C7_BASE, SysCtlClockGet(), false);
}
void SCCB_set(uint8_t address, uint8_t reg, uint8_t data)
{
/*
* Specify that we want to communicate to device address with an intended write to bus
*/
I2CMasterSlaveAddrSet(I2C7_BASE, address, false);
/*
* Register to be read
*/
I2CMasterDataPut(I2C7_BASE, reg);
/*
* Send control byte and register address byte to slave device
*/
I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_BURST_SEND_START);
/*
* Wait for MCU to finish transaction
*/
while(I2CMasterBusy(I2C7_BASE));
/*
* Specify data to be written to the above mentioned register
*/
I2CMasterDataPut(I2C7_BASE, data);
/*
* Send data to slave
*/
I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
/*
* Wait for MCU & device to complete transaction
*/
while(I2CMasterBusy(I2C7_BASE));
}
uint8_t SCCB_get(uint8_t address, uint8_t reg)
{
I2CMasterSlaveAddrSet(I2C7_BASE, address, false);
I2CMasterDataPut(I2C7_BASE, reg);
I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C7_BASE));
I2CMasterSlaveAddrSet(I2C7_BASE, address, true);
I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(I2C7_BASE));
return(I2CMasterDataGet(I2C7_BASE));
}
void main(void)
{
BasicConfig();
UARTConfig();
I2CConfig();
SCCB_set(0x68, 0x02, 0x01); // hour
SCCB_set(0x68, 0x01, 0x01); // minute
SCCB_set(0x68, 0x00, 0x05); // second
while(1)
{
UARTprintf("\n%02d", SCCB_get(0x68, 0x02));
UARTprintf("-%02d", SCCB_get(0x68, 0x01));
UARTprintf("-%02d", SCCB_get(0x68, 0x00));
SysCtlDelay(SysCtlClockGet());
}
}