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.

I2C question of lm4f120 launchpad

I'm debugging ADXL345 using i2c with lm4f120h5qr,

here is the init code:

  ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |           //80mhz
                       SYSCTL_OSC_MAIN);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
  GPIOPinConfigure(GPIO_PB2_I2C0SCL);
  GPIOPinConfigure(GPIO_PB3_I2C0SDA);
  GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
  GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2 );
  I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), true);        //400kbps
  ROM_SysCtlDelay(10000);
  I2CMasterEnable(I2C0_MASTER_BASE);

here is the driver code:

this is used for reading X-ACCEL-FIFO ,the two regs of adxl345.

unsigned long ADXL_Read_X(void)
{
  unsigned long back2,m;
  unsigned long back1;
  I2CMasterSlaveAddrSet(I2C0_MASTER_BASE,SlaveAddress,false);
  I2CMasterDataPut(I2C0_MASTER_BASE,0x32);
  I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_SEND_START);
  while(I2CMasterBusy(I2C0_MASTER_BASE));
  I2CMasterSlaveAddrSet(I2C0_MASTER_BASE,SlaveAddress,true);
  I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START);
  while(I2CMasterBusy(I2C0_MASTER_BASE));
  back1=I2CMasterDataGet(I2C0_MASTER_BASE);
  I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);
  while(I2CMasterBusy(I2C0_MASTER_BASE));
  back2=I2CMasterDataGet(I2C0_MASTER_BASE);
  I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
  while(I2CMasterBusy(I2C0_MASTER_BASE));
  m=(back2<<8)|back1;
  return(m);
}

there is nothing wrong with back1,but back2's value is always 0 .it confused me ... = =...

  •   I2CMasterSlaveAddrSet(I2C0_MASTER_BASE,SlaveAddress,false);
      I2CMasterDataPut(I2C0_MASTER_BASE,0x32);
      I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_SEND_START);
      while(I2CMasterBusy(I2C0_MASTER_BASE));
      I2CMasterSlaveAddrSet(I2C0_MASTER_BASE,SlaveAddress,true);
      I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START);
      while(I2CMasterBusy(I2C0_MASTER_BASE));
      back1=I2CMasterDataGet(I2C0_MASTER_BASE);
      I2CMasterControl(I2C0_MASTER_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
      while(I2CMasterBusy(I2C0_MASTER_BASE));
      back2=I2CMasterDataGet(I2C0_MASTER_BASE);
      m=(back2<<8)|back1;
      return(m);

    This won't work too,,this time,back2 is unavailable....

  • Hello Zheng,

    I could not notice any glaring problem with the code that you posted. You say you are able to get the first byte of data. Does it look sensible? Do you have the correct pull ups connected to the I2C pins?

    Since I don't have much information on the debug steps, I would like to point you to another post on I2C that might help in further debug. You might also want to take a look at the I2C master driver that is provided with the TivaWare

    Regards,
    Sai
  • Hi Sai~~

    I found nothing wrong with my code too, so i tried it on MPU6050 and it works.perfectly.

    so I contacted the seller of adxl345 model, he recalled it , and i'm waiting for it ~~~~.

    Thank you very much~