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.

I2C0 code not working for stellaris LM4F232H5QD

Hi,

I trying to configure I2C0 communication between LM4F232H5QD and  audio controller. I have to configure controller as master.

I have to send two bytes to Audio controller and read 1 byte from the same. My I2C0 code is not working, please help. it's urgent. my code is as follows.

If any one has working I2C0 code for LM4F232H5QD please share it. (Xtal freq = 16MHz)

#include "hw_memmap.h"
#include "hw_types.h"
#include "sysctl.h"
#include "gpio.h"
#include "i2c.h"
#include "hw_i2c.h"
#include "lm4f232h5qd.h"

#define SLAVE_ADDRESS 0xC0

void InitSystem(void);

int main(void)
{
 unsigned long ulRecData;
 unsigned long ulMasterData[2] = {0x00, 0xAA};

 InitSystem();

  I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false);

  I2CMasterDataPut(I2C0_MASTER_BASE, ulMasterData[0]);
 
  I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);

  while(I2CMasterBusBusy(I2C_MASTER_BASE))
  {
  }

  I2CMasterDataPut(I2C0_MASTER_BASE, ulMasterData[1]);

   I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);

  
  while(I2CMasterBusBusy(I2C_MASTER_BASE))
  {
  }

/* Read the data */

 I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, true);

  
  I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);

  
  while(I2CMasterBusBusy(I2C_MASTER_BASE))
  {
  }

   ulRecData = I2CMasterDataGet(I2C0_MASTER_BASE);
 }

 

void InitSystem(void)
{

 /* Set the clock to run directly from the external crystal/oscillator. */
 SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC |
       SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

 /* Enable I2C0 peripheral. */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

    /* I2C0 is used with port B[3:2]. GPIO port B is enabled. */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    /*
     * Configure the pin muxing (alternate function of pins)
     * for I2C0 functions on port B2 and B3.
     *
     * By default on reset PB2 and PB3 are configured for I2C
     * functionality.
     */

    GPIOPinConfigure(GPIO_PB2_I2C0SCL);
    GPIOPinConfigure(GPIO_PB3_I2C0SDA);

    /*
     * Select the I2C function for these pins.
     */


    GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);


    I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);
  }