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

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

$
0
0

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);

//rtc_write();

I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false); // Write
while(I2CMasterBusy(I2C0_MASTER_BASE)) {}

I2CMasterDataPut(I2C0_MASTER_BASE, 0x00); // Address Offset
// Initiate send of character from Master to Slave

I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_SEND_START); //0x003

while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

I2CMasterDataPut(I2C0_MASTER_BASE, 0x09); // Seconds
// Initiate send of character from Master to Slave
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

I2CMasterDataPut(I2C0_MASTER_BASE, 0x05); // Minutes

// Initiate send of character from Master to Slave

I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

I2CMasterDataPut(I2C0_MASTER_BASE, 0x09); // hours

// Initiate send of character from Master to Slave
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
while(1)
{
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, true); // Read Start
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

timeformat[0]=I2CMasterDataGet(I2C0_MASTER_BASE); //Receive zero byte
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[0]);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

timeformat[1]=I2CMasterDataGet(I2C0_MASTER_BASE); //Receive zero byte
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[1]);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

timeformat[2]=I2CMasterDataGet(I2C0_MASTER_BASE); //Receive zero byte
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[2]);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

timeformat[3]=I2CMasterDataGet(I2C0_MASTER_BASE); //Receive zero byte
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[3]);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

}
}


Viewing all articles
Browse latest Browse all 216526

Trending Articles



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