ICM-20948 driver firmware upload fails.

By andrevs , 11 September 2018

Hello.
I have an ICM-20948 Evaluation Board (https://store.invensense.com/Products/Detail/EVICM20948-TDK-InvenSense/597422/) connected through a level shifter (https://www.adafruit.com/product/757) to a nRF52-DK. I have ported the Discovery Board driver to the nRF52 (https://www.invensense.com/developers/software-downloads/#sla_content_35656)

Now I have a problem during the initialisation. In the file inv_mems_load_firmware.c, function inv_mems_firmware_load(), the firmware is being uploaded, and then being verified. This verify always fails on the first packet on 16 bytes. The data read back always differs from the expected data.

See the attached file i2c.c for my code to support the nrf52. Is there anything I am overlooking here? Or could it be my level shifter is distorting the signal?

andrevs

7 years 6 months ago

C source code cannot be uploaded for security reasons it seems? Then this is the code as text

unsigned long ST_Sensors_I2C_WriteRegister(unsigned char Address, unsigned char RegisterAddr, unsigned short RegisterLen, const unsigned char *RegisterValue)
{
int ret = nrf_drv_twi_tx(&m_twi, Address, &RegisterAddr,1,true);
if (ret) return ret;
ret = nrf_drv_twi_tx(&m_twi, Address, RegisterValue,RegisterLen,false);
return ret;
}

unsigned long ST_Sensors_I2C_ReadRegister(unsigned char Address, unsigned char RegisterAddr, unsigned short RegisterLen, unsigned char *RegisterValue)
{
int ret = nrf_drv_twi_tx(&m_twi, Address, &RegisterAddr,1,true);
if (ret) return ret;
ret = nrf_drv_twi_rx(&m_twi, Address, RegisterValue,RegisterLen);
return ret;

}

phpbb Post ID
37081

loganbenda

7 years 1 month ago

Hi,

I just was working through the same problem. I used information found in this post: https://www.invensense.com/developers/forums/topic/icm-20948-dmp-flash-error-2/ Particularly I used a different write sequence (and ic library) which Dingari had modified in the following github location: https://github.com/jrowberg/i2cdevlib/pull/360

The code I used was the following (note that this is for a nRF based device).


/** Read single byte from an -bit device register.
* @param devAddr IC slave device address
* @param regAddr Register regAddr to read from
* @param data Container for byte value read from device
* @param timeout Optional read timeout in milliseconds ( to disable, leave off to use default class value in ICdev::readTimeout)
* @return Status of read operation (true = success)
*/
int_t ICdev::readByte(uint_t devAddr, uint_t regAddr, uint_t *data, uint_t timeout) {
return readBytes(devAddr, regAddr, , data, timeout);
}

/** Read multiple bytes from an -bit device register.
* @param devAddr IC slave device address
* @param regAddr First register regAddr to read from
* @param length Number of bytes to read
* @param data Buffer to store read data in
* @param timeout Optional read timeout in milliseconds ( to disable, leave off to use default class value in ICdev::readTimeout)
* @return IC_TransferReturn_TypeDef http://downloads.energymicro.com/documentation/doxygen/group__IC.html
*/
int_t ICdev::readBytes(uint_t devAddr, uint_t regAddr, uint_t length, uint_t *data, uint_t timeout) {

//bool transfer_succeeded;
nrf_drv_twi_tx(&m_twi,devAddr,®Addr,,false);
//transfer_succeeded = twi_master_transfer(m_device_address, ®ister_address, , TWI_DONT_ISSUE_STOP);

ret_code_t r= nrf_drv_twi_rx(&m_twi,devAddr,data,length);

//transfer_succeeded &= twi_master_transfer(m_device_address|TWI_READ_BIT, destination, number_of_bytes, TWI_ISSUE_STOP);
return r==NRF_SUCCESS;

}

/** Write multiple bytes to an -bit device register.
* @param devAddr IC slave device address
* @param regAddr First register address to write to
* @param length Number of bytes to write
* @param data Buffer to copy new data from
* @return Status of operation (true = success)
*/
bool ICdev::writeBytes(uint_t devAddr, uint_t regAddr, uint_t length, const uint_t* data) {

const uint_t buf_len = length+; // Register address + number of bytes
uint_t tx_buf[buf_len];

tx_buf[] = regAddr;

memcpy(tx_buf+, data, length);

return NRF_SUCCESS == nrf_drv_twi_tx(&m_twi, devAddr, tx_buf, buf_len, true);

}

phpbb Post ID
37282
phpbb Topic ID
37080