Quantcast
Channel: Microcontrollers
Viewing all articles
Browse latest Browse all 216424

Forum Post: hi, im writing a code to get data from rtc(bq32002)to lx4f232h through I2C .im able to write to rtc and get acknowledgement but unable to get data from rtc.pls refer to the code below.

$
0
0

int
main(void)
{
//unsigned long ulDataTx;

unsigned int i;

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);

GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_2);

HWREG(I2C0_MASTER_BASE + I2C_O_MCR) |= 0x01;

IntEnable(INT_I2C0);

I2CSlaveIntEnableEx(I2C0_SLAVE_BASE, I2C_SLAVE_INT_DATA);

I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);

I2CSlaveEnable(I2C0_SLAVE_BASE);

I2CSlaveInit(I2C0_SLAVE_BASE, SLAVE_ADDRESS);

I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false);

InitConsole(); //uart init

IntMasterEnable();

// Display the example setup on the console.
//
UARTSend((unsigned char*)"I2C Slave Interrupt Example ->",40);
delay();
UARTSend((unsigned char*)"\n Module = I2C0",20);
delay();
UARTSend((unsigned char*)"\n Mode = Receive interrupt on the Slave module",50);
delay();
UARTSend((unsigned char*)"\n Rate = 100kbps\n\n",35);

//
// Initialize the data to send.
//
//ulDataTx = 'S';

UARTSend((unsigned char*)"Transferring from: Master -> Slave\n",50);
delay();
//
// Display the data that I2C0 is transferring.
//
// UARTSend((unsigned char*)" Sending: '%c'", ulDataTx);

for (i=0;i<9;i++)
{
ROM_UARTCharPutNonBlocking(UART7_BASE, rtc_timedate[i]);
//
// Place the data to be sent in the data register.
//

I2CMasterDataPut(I2C0_MASTER_BASE, rtc_timedate[i]);

I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);

Receive_Data[i] = I2CMasterDataGet(I2C0_MASTER_BASE);
}
timeformat[0]=((Receive_Data[2]& 0x10)>>4)+0x30;
timeformat[1]=(Receive_Data[2]& 0x0f)+0x30;

ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[0]);
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[1]);

timeformat[2]= ((Receive_Data[1]& 0x70)>>4)+0x30;
timeformat[3]=(Receive_Data[1]& 0x0f)+0x30;

ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[2]);
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[3]);

timeformat[4]= ((Receive_Data[0]& 0x70)>>4)+0x30;
timeformat[5]=(Receive_Data[0]& 0x0f)+0x30;

ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[4]);
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[5]);

while(1)

{

}

i'm getting 000000 as my result


Viewing all articles
Browse latest Browse all 216424

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>