[NHS3100] I2C driver in "app_demo_dp_tlogger"

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

[NHS3100] I2C driver in "app_demo_dp_tlogger"

1,140 Views
aresmarser
Contributor III

Hi Sir,

I am now woking on NHS3100 with LPCXpresso IDE.

I downloaded the SDK "release_mra2_10_1_nhs3100.zip" and imported into my LPC workspace.

We connected an acceleration sensor on NHS3100 board with I2C interface.

My trouble is that I am not sure how to drive the sensor with I2C on my project based on "app_demo_dp_tlogger".

I studied some documents and code in the SDK but I am still confused.

For example,

Should I add the module "i2cio" in the project "app_demo_dp_tlogger"?

Shoud I init I2C in the main function in the file “maintlogger.c”?

Or it is ok to just call some API function to read/write the sensor?

For example, the sensor read address is 0x33, one of the register of the sensor is 0x0F, how should I do (config/function call/...) step by step to get the sensor register value?

Sorry but I am a little new in the scope.

Really need your support and guide.

Thanks,

Arna

2 Replies

888 Views
aresmarser
Contributor III

Hi Ivan, Sir,

 
I read the examples and study some documents.
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 based on "app_example_dp_i2c" to test:
------
// 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);
}
------

It is very appreciated if anyone can help me to review if anything wrong.
And any limitation to use the I2C API?
Thanks,
Arna
0 Kudos

888 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.