This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

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.

hi,

   i am not actually where the problem is i used the correct slave address also that is 0xD0.

void RTC_read()
{
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 1stbyte
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 2nd byte
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[2]);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}

timeformat[3]=I2CMasterDataGet(I2C0_MASTER_BASE); //Receive 3rd byte
ROM_UARTCharPutNonBlocking(UART7_BASE, timeformat[3]);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
}
//*****************************************************************************
//
// Configure the I2C0 master and slave and connect them using loopback mode.
//
//*****************************************************************************

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

//ulDataTx = 'S';

UARTSend((unsigned char*)"Transferring from: Master -> Slave\n",50);
delay();

rtc_write();
while(1)
{

RTC_read();

}
}

void 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, 0x01); // 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, 0x02); // 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))
{
}
}

  • Hi,

    I only noticed this below.

    shyam reddy said:

    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

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

    Try this below instead.

    GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    I have not checked the rest of the code.

    -kel

  • hi

     still its not working and getting in to interrupt handler after this send start in master busy loop

     I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_SEND_START); //0x003

    while(I2CMasterBusy(I2C0_MASTER_BASE))
    {
    }

    can i know why the it is happens and in which cases the master will be busy....