[NHS3100] Questions/Issues about I2C driver

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

[NHS3100] Questions/Issues about I2C driver

1,308 Views
aresmarser
Contributor III

Hi Sir,

I am woking on NHS3100 and I added an accelerometer sensor LIS3DH.

I added my sensor test code based on "app_example_dp_i2c" from the NHS3100 SDK "release_mra2_10_1_nhs3100.zip".

Now I can read/write the register of the sensor by calling the I2C API funciton "Chip_I2C_MasterCmdRead"/"Chip_I2C_MasterSend" respectively.

But the problem I met is that I canNOT operate the I2C by calling  the API functions above repeatedly.

My test items/steps are:

1. send data to I2C slave to get the register data of the sensor by call "Chip_I2C_MasterCmdRead";

2. send data to I2C slave to write the register of the sensor by call "Chip_I2C_MasterSend";

3. send data to I2C slave to get the register data of the sensor again by call "Chip_I2C_MasterCmdRead";

If I just have only item 1 (or 2, or 3) to test, it is ok for the correct operation and result.

But when I have the three items to test together, it is failed to operate the item 2 and item 3 for the results.

The API function never return for item 2 and item 3.

And here are the code snippets:

------

// for test item 1. send data to I2C slave to get the register data of the sensor by call "Chip_I2C_MasterCmdRead";
static void Slave0Access(void)
{
    uint8_t slaveAddr = 0x19;
    uint8_t regAddr = 0x20;  // 0x0F;
 uint8_t readData = 0;
//    printf("Slave0Access\r\n");
  
    Chip_I2C_MasterCmdRead(I2C0, slaveAddr,  (uint8_t *)&regAddr, (uint8_t *)&readData, 1);
//    printf("Read slaveAddr 0x%02X, regAddr 0x%02X, readData 0x%02X\n\r", slaveAddr, regAddr, readData);
}
// for test item 2. send data to I2C slave to write the register of the sensor by call "Chip_I2C_MasterSend";
static void Slave1Access(void)
{
   uint8_t slaveAddr = 0x19;
   uint8_t regAddr = 0x20;
   uint8_t writeData = 0x57;
   uint8_t txBuf[2] = {0x00};
//   printf("Slave1Access\r\n");
  
   txBuf[0] = regAddr;
   txBuf[1] = writeData;
  
   Chip_I2C_MasterSend(I2C0, slaveAddr,txBuf, 2);
//   printf("Write slaveAddr 0x%02X, regAddr 0x%02X, writeData 0x%02X\n\r", slaveAddr, regAddr, writeData);
}
// for test item 3. send data to I2C slave to get the register data of the sensor again by call "Chip_I2C_MasterCmdRead";
static void Slave2Access(void)
{
 uint8_t slaveAddr = 0x19;
 uint8_t regAddr = 0x20;
 uint8_t readData = 0;
// printf("Slave2Access\r\n");
 Chip_I2C_MasterCmdRead(I2C0, slaveAddr,  (uint8_t*)&regAddr, (uint8_t*)&readData, 1);
// printf("Read slaveAddr 0x%02X, regAddr 0x%02X, readData 0x%02X\n\r", slaveAddr, regAddr, readData);
}
// here is the calling for test 1, 2, 3:
void Master_PollSlaves(void)
{
//    printf("Master_PollSlaves\n\r");
    /** Device Id Use Case*/
    Slave0Access();
    /** Temperature Use Case */
    Slave1Access();
    /** LED Use Case */
    Slave2Access();
    /** Scratchpad/Counter Use Case */
//    Slave3Access();
//    Chip_Clock_System_BusyWait_ms(I2C_MASTER_COMM_INTERVAL);
}
------
The whole project is attached:
(1) "original_code_from_SDK.7z"
(2) "workspace_sensor_test_code.7z"
It is very appreciated if anyone can help me to review if anything wrong.
Thanks,
Arna
Tags (2)
0 Kudos
Reply
2 Replies

979 Views
IvanRuiz
NXP Employee
NXP Employee

Hello,

 

Please refer to the app_example_dp_i2c example. This example demonstrates the configuration of the I2C for Master and Slave functionality. You will find it in the following path:

...\release_mra2_10_1_nhs3100.zip\release_mra2_10_1_nhs3100\sw\nss\app_example_dp_i2c

 

 

Regards,

Ivan.

0 Kudos
Reply

979 Views
aresmarser
Contributor III

Anyone has suggestion?

0 Kudos
Reply