hi,
i am using the TM4C123GH6PM microcontoller . (Tiva c launchpad).
i am trying to communicate with an RTC module (DS3231) , using i2c communication.
i am trying the example code. (master slave loop back mechanism).
now i am trying with out loop back mechanism . simple master slave transmission and reception. (i dissable the loopback mechanism).
but i can not transmit any data to the RTC module. i copy my code in below.
is there any mistake is there means any one please suggest me any solution to me.
program:
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#define NUM_I2C_DATA 8
#define SLAVE_ADDRESS 0xD0 // slave address
void
InitConsole(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioConfig(0, 115200, 16000000);
}
int main(void)
{
uint32_t ui32Index = 0;
uint32_t pui32DataTx[8] = {0};
uint32_t pui32DataRx[8] = {0};
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
I2CSlaveEnable(I2C0_BASE);
I2CSlaveInit(I2C0_BASE, SLAVE_ADDRESS);
I2CMasterSlaveAddrSet(I2C0_BASE, SLAVE_ADDRESS, false); // for write
InitConsole();
pui32DataTx[0] = 'I';
I2CMasterDataPut(I2C0_BASE, pui32DataTx[ui32Index]);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(!(I2CSlaveStatus(I2C0_BASE) & I2C_SLAVE_ACT_RREQ)) // my code will stuck here only. after this it not moving.
{
}
pui32DataRx[ui32Index] = I2CSlaveDataGet(I2C0_BASE);
while(I2CMasterBusy(I2C0_BASE))
{
}
}
Regards
Arun Kumar.N