FXLS8471Q i2c communication sample

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FXLS8471Q i2c communication sample

Jump to solution
860 Views
piotrrosenbaum
Contributor I

Hi !

I Can't communicate with FXLS8471Q via i2c. I want to read WHO_I_AM register but device don't respond.

After read who value is 255. Can You show me a example code how to read it ?

#define FXLS8471Q_SLAVE_ADDR       0x1E

#define FXLS8471Q_WHOAMI     0x0D

void FXLS_init(void) {

    uint8_t who;

    Soft_I2C1_send_address(FXLS8471Q_SLAVE_ADDR);

    Soft_I2C1_send_data(FXLS8471Q_WHOAMI, END);

    Soft_I2C1_send_address(FXLS8471Q_SLAVE_ADDR);

    Soft_I2C1_send_data(0x00, END);

    who = Soft_I2C1_read_data(END);

}

Tags (2)
0 Kudos
1 Solution
434 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Piotr,

Here is an example code to read the WHO_AM_I register (0x0D) using I2C when SA0 = SA1 = 0.

//FXLS8471Q 7-bit I2C address

#define FXLS8471Q_I2C_ADDRESS   0x1E // SA0 pin = SA1 = 0 -> 7-bit I2C address is 0x1E

who_am_i = I2C_ReadRegister(FXLS8471Q_I2C_ADDRESS, 0x0D);

unsigned char I2C_ReadRegister(unsigned char u8SlaveAddress, unsigned char u8RegisterAddress)

{

  unsigned char result;

  

  I2C_Start();         

  I2C0_D = u8SlaveAddress << 1; /* Send I2C device address with W/R bit = 0 */

  I2C_Wait();

  I2C0_D = u8RegisterAddress; /* Send register address */

  I2C_Wait();

  I2C_RepeatedStart();

  I2C0_D = (u8SlaveAddress << 1) | 0x01; /* Send I2C device address this time with W/R bit = 1 */

  I2C_Wait();

  I2C_EnterRxMode();

  I2C_DisableAck();

  result = I2C0_D;

  I2C_Wait();

  I2C_Stop(); 

  result = I2C0_D;

  Pause(50);

  return result;

}

A copy from the data sheet:

Single byte read_text.JPG

Single byte read.JPG

I hope it helps.

Regards,

Tomas

PS: If my answer helps to solve your question, please mark it as "Correct". Thank you.

View solution in original post

0 Kudos
1 Reply
435 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Piotr,

Here is an example code to read the WHO_AM_I register (0x0D) using I2C when SA0 = SA1 = 0.

//FXLS8471Q 7-bit I2C address

#define FXLS8471Q_I2C_ADDRESS   0x1E // SA0 pin = SA1 = 0 -> 7-bit I2C address is 0x1E

who_am_i = I2C_ReadRegister(FXLS8471Q_I2C_ADDRESS, 0x0D);

unsigned char I2C_ReadRegister(unsigned char u8SlaveAddress, unsigned char u8RegisterAddress)

{

  unsigned char result;

  

  I2C_Start();         

  I2C0_D = u8SlaveAddress << 1; /* Send I2C device address with W/R bit = 0 */

  I2C_Wait();

  I2C0_D = u8RegisterAddress; /* Send register address */

  I2C_Wait();

  I2C_RepeatedStart();

  I2C0_D = (u8SlaveAddress << 1) | 0x01; /* Send I2C device address this time with W/R bit = 1 */

  I2C_Wait();

  I2C_EnterRxMode();

  I2C_DisableAck();

  result = I2C0_D;

  I2C_Wait();

  I2C_Stop(); 

  result = I2C0_D;

  Pause(50);

  return result;

}

A copy from the data sheet:

Single byte read_text.JPG

Single byte read.JPG

I hope it helps.

Regards,

Tomas

PS: If my answer helps to solve your question, please mark it as "Correct". Thank you.

0 Kudos