AnsweredAssumed Answered

I2C on LPC810/LPC812

Question asked by Stefanos Kiakas on Jul 1, 2016
Latest reply on Sep 29, 2016 by Tiago Fernandes

I got the blink LED program to work and have been able to use the LPC810/812 to control WS2812 LED. Now I want to add some more functionality by using the I2C ROM API using LPCOpen. Unfortunately I am experiencing some issues in getting the I2C functionality to work on the LPC810/812.

 

I have hooked up a scope to the SDA/SCL pins but I see no activity on the pins. Here is the code I am using to try and read the sensor.

 

I created the following code based on the examples provided for LPCOpen, to read an I2C sensor, an infrared temperature sensor made my Melexis MLX90614. The readI2C() function is only returning one byte for now for testing purposes. I am only including the I2C portion of the code, which should be reading the sensor using the I2C bus.

 

I am wondering why I am not seeing any signal on the scope for the SDA/SCL lines? Can someone provide me with a link to a working example of using the I2C bus with the LPC810/812 using LPCOpen?

 

Thank you,

Stefanos

 

-----------

#include "chip.h"

#include <cr_section_macros.h>

 

#define I2C_BITRATE  (100000)

 

#define I2C_ADDR_TSENSOR   (0x5a)

#define TSENSOR_ADDR       (0x06)

 

#define TICKRATE_HZ        (10)

 

 

static I2C_HANDLE_T *i2cMaster;

static uint32_t      i2cMasterBuffer[0x20];

 

 

static void initializeSWM()

{

  Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);

 

/* Connect the I2C_SDA and I2C_SCL signals to port pins(P0.10, P0.11) */

  Chip_SWM_MovablePinAssign(SWM_I2C_SDA_IO, 10);

  Chip_SWM_MovablePinAssign(SWM_I2C_SCL_IO, 11);

  Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);

}

 

 

static void initializeI2C()

{

    Chip_I2C_Init(LPC_I2C);

    i2cMaster = LPC_I2CD_API->i2c_setup(LPC_I2C_BASE, i2cMasterBuffer);

    LPC_I2CD_API->i2c_set_bitrate(i2cMaster, Chip_Clock_GetSystemClockRate(), I2C_BITRATE);

}

 

 

void delay(count)

{

  while(--count>=0)

  {

  __WFI();

  }

}

 

static uint8_t readI2C()

{

  uint8_t rxData[10];

I2C_PARAM_T param;

I2C_RESULT_T result;

 

  rxData[0] = I2C_ADDR_TSENSOR;

  rxData[1] = TSENSOR_ADDR;

 

  param.num_bytes_send = 0;

  param.num_bytes_rec = 3;

  param.buffer_ptr_rec = &rxData[0];

  param.stop_flag = 1;

 

  LPC_I2CD_API->i2c_set_timeout(i2cMaster, 100000);

  LPC_I2CD_API->i2c_master_receive_poll(i2cMaster, &param, &result);

  return (uint8_t) rxData[0];

}

 

 

 

 

int main(void) {

 

 

    SystemCoreClockUpdate();

 

 

    initializeSWM();

    initializeI2C();

 

    SysTick_Config(SystemCoreClock / TICKRATE_HZ);

    // Force the counter to be placed into memory

    volatile static int i = 0 ;

    // Enter an infinite loop, just incrementing a counter

    while(1) {

        i++ ;

        readI2C();

        delay(10);

   }

    return 0 ;

}

Outcomes