I´m currently developing basic routines in order to communicate with an IMU or Inertial Measurement Unit, the ICM20948 from TDK - InvenSense using the I2C protocol through a PCB I have develop myself, I currently have functions to communicate with it like:
int writeRegister(uint8 slaveAdress, uint8 registerAdress, uint8 data);
uint8 readRegisters(uint8 slaveAdress, uint8_t subAddress, uint8 count, uint8 dest);
int selectAutoClockSource(uint8 slaveAdress)
And some more which are working properly (I have read registers who tell me this is working) the point is that the ICM20948 datasheet device doesn´t specifies me the order to configurate it in order to read the acceleration data, I have found a code on a GitHub, more concretely https://github.com/dtornqvist/icm-20948-arduino-library which is written in Arduino, I tried to port it to c, the language I'm currently using on it, getting the current configuration function
int begin(uint8 slaveAdress){
if (changeUserBank_force(slaveAdress, USER_BANK_0) < 0) {
return -1;
}
if (selectAutoClockSource(slaveAdress) < 0) {
return -2;
}
// enable I2C master mode
if(enableI2cMaster(slaveAdress) < 0){
return -3;
}
if (powerDownMag(slaveAdress) < 0) {
return -4;
}
reset(slaveAdress);
CyDelay(10);
if (selectAutoClockSource(slaveAdress) < 0) {
return -6;
}
whoAreU(slaveAdress);
if(enableAccelGyro(slaveAdress, UB0_PWR_MGMNT_2, UB0_PWR_MGMNT_2_SEN_ENABLE) == 1){
} else {
UART_DEBUG_PutString("\r\n Error al habilitar el giroscopio y acelerometro");
return -7;
}
if(configAccel(slaveAdress, ACCEL_RANGE_2G, ACCEL_DLPF_BANDWIDTH_246HZ) != 1){
return -8;
}
if (setAccelSrd(slaveAdress,0) < 0) {
return -12;
}
return 1;
}
After that I call my:
int16_t getAccelX_mss(uint8 slaveAdress){
uint8 _axcountsH, _axcountsL;
int16_t _axcounts;
if (changeUserBank_force(slaveAdress, USER_BANK_0) < 0) {
return -1;
}
_axcountsH = readRegisters(slaveAdress, 0x45u, 1, _axcountsH);
_axcountsL = readRegisters(slaveAdress, 0x46u, 1, _axcountsL);
_axcounts = (((int16_t)_axcountsH) << 8) | _axcountsL;
sprintf(Rx_aux, " 0x%d ", _axcounts);
UART_DEBUG_PutString("\r\n Acce Read: ");
UART_DEBUG_PutString(Rx_aux);
return 1;
}
Function, which is supposed to return me trough UART the mix of 45u and 46u (acceleration) registers info, but I'm receiving the next output (I'm using Hterm 0.8.3 to capture the uart output)
UART ok...<\r><\n>
Begin.<\r><\n>
Begin with no errors.<\r><\n>
Acce Read: 0x0
I have no real clue about, even when I move my pcb, generating an acceleration the result keeps as 0x0. Have anyone worked with this class of software and can give me some advice about how to keep working? Or I have any important error on my code that I haven't seen?