AnsweredAssumed Answered

Using Accelerometer(MMA8652FC) of lpc54618 eval-kit

Question asked by Subodh Mankar on Aug 7, 2017
Latest reply on Aug 21, 2017 by Subodh Mankar

Hi,

I am referring :- MMA8652FC - Bare metal example project  for developing application based on accelerometer.

Following is the code which I am trying to use to read data from sensor.

 

 

#define EXAMPLE_I2C_MASTER_BASE (I2C2_BASE)                  /*FLEXCOMM2 I2C*/

#define I2C_MASTER_CLOCK_FREQUENCY (12000000)   

#define I2C_SLAVE_CLOCK_FREQUENCY (12000000)

 

#define EXAMPLE_I2C_MASTER ((I2C_Type *)EXAMPLE_I2C_MASTER_BASE)

 

#define I2C_MASTER_SLAVE_ADDR_7BIT (0x1DU)

#define I2C_BAUDRATE (100000) /* 100K */

#define I2C_DATA_LENGTH (8) /* MAX is 256 */

.

.

.

 

i2c_master_config_t masterConfig;

 

I2C_MasterGetDefaultConfig(&masterConfig);

 

/* Change the default baudrate configuration */

masterConfig.baudRate_Bps = I2C_BAUDRATE;

/* Initialize the I2C master peripheral */

I2C_MasterInit(EXAMPLE_I2C_MASTER, &masterConfig, I2C_MASTER_CLOCK_FREQUENCY);

/* Create the I2C handle for the non-blocking transfer */   

I2C_MasterTransferCreateHandle(EXAMPLE_I2C_MASTER, &g_m_handle, NULL, NULL);

 

/* Setup the master transfer */

masterXfer.slaveAddress = I2C_MASTER_SLAVE_ADDR_7BIT;

masterXfer.direction = kI2C_Read;

masterXfer.subaddress = 0;

masterXfer.subaddressSize = 0;

masterXfer.data = g_master_buff;

masterXfer.dataSize = I2C_DATA_LENGTH;

masterXfer.flags = kI2C_TransferDefaultFlag;

/* Send master non-blocking data to slave */

reVal = I2C_MasterTransferNonBlocking(EXAMPLE_I2C_MASTER, &g_m_handle, &masterXfer);

if (reVal != kStatus_Success)

{

   break;

}

 

/* Receive Data. */

if ((masterXfer.direction == kI2C_Read) && (masterXfer.dataSize > 0))

{

   result = I2C_MasterReadBlocking(EXAMPLE_I2C_MASTER, &g_master_buff, masterXfer.dataSize, masterXfer.flags);

}

 

I am still unable to read data from sensor.

What should I use to initialize sensor and get data from it?? [just like example provided in MMA8652FC - Bare metal example project]

 

 

As shown in document :- MMA8652FC - Bare metal example project

void MMA8652FC_Init (void)

{

   I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG2, 0x40); // Reset all registers to POR values

   Pause(0x631); // ~1ms delay

   I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, XYZ_DATA_CFG_REG, 0x00); // +/-2g range with ~0.977mg/LSB

   I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG2, 0x02); // High Resolution mode

   I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG3, 0x00); // Push-pull, active low interrupt

   I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG4, 0x01); // Enable DRDY interrupt

   I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG5, 0x01); // DRDY interrupt routed to INT1 - PTA5

   I2C_WriteRegister(MMA8652FC_I2C_ADDRESS, CTRL_REG1, 0x39); // ODR = 1.56Hz, Active mode

}

 

PINMUX SETUP:-

 

const uint32_t port3_pin23_config = (

IOCON_PIO_FUNC1 | /* Pin is configured as FC2_TXD_SCL_MISO */

IOCON_PIO_MODE_PULLUP | /* Selects pull-up function */

IOCON_PIO_INV_DI | /* Input function is not inverted */

IOCON_PIO_DIGITAL_EN | /* Enables digital function */

IOCON_PIO_INPFILT_OFF | /* Input filter disabled */

IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */

);

IOCON_PinMuxSet(IOCON, PORT3_IDX, PIN23_IDX, port3_pin23_config); /* PORT3 PIN22 (coords: N5) is configured as FC2_TXD_SCL_MISO */

 

const uint32_t port3_pin24_config = (

IOCON_PIO_FUNC1 | /* Pin is configured as FC2_TXD_SCL_MISO */

IOCON_PIO_MODE_PULLUP | /* Selects pull-up function */

IOCON_PIO_INV_DI | /* Input function is not inverted */

IOCON_PIO_DIGITAL_EN | /* Enables digital function */

IOCON_PIO_INPFILT_OFF | /* Input filter disabled */

IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */

);

IOCON_PinMuxSet(IOCON, PORT3_IDX, PIN24_IDX, port3_pin24_config); /* PORT3 PIN22 (coords: N5) is configured as FC2_TXD_SCL_MISO */

 

const uint32_t port3_pin4_config = (

IOCON_PIO_FUNC0 | /* Pin is configured as PIO3_14 */

IOCON_PIO_MODE_PULLUP | /* Selects pull-up function */

IOCON_PIO_INV_DI | /* Input function is not inverted */

IOCON_PIO_DIGITAL_EN | /* Enables digital function */

IOCON_PIO_INPFILT_OFF | /* Input filter disabled */

IOCON_PIO_SLEW_STANDARD | /* Standard mode, output slew rate control is enabled */

IOCON_PIO_OPENDRAIN_DI /* Open drain is disabled */

);

IOCON_PinMuxSet(IOCON, PORT3_IDX, PIN4_IDX, port3_pin4_config); /* PORT3 PIN14 (coords: E3) is configured as PIO3_14 */

 

Where should I modify my code so that I can make it work with sdk2.2 for lpc54618?

Outcomes