2020-04-16 11:13 AM
Hi,
I've bought a ST MKI179V1 board to interface via I2C with a Nucelo-L433RC . Furthermore, I'm using ST oficial drivers to MEMS sensors. The problem is when I try to read the register it always return 0. I've already made a lot of tests and I can't discover the problem. For me it looks to be so simple but I'm not makinng this work.
I let you my schematic:
And my simplified code:
static uint8_t whoamI;
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len);
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len) {
HAL_I2C_Mem_Read(handle, LIS2DW12_I2C_ADD_L, reg, I2C_MEMADD_SIZE_16BIT,
bufp, len, 1000);
return 0;
}
int main(void){
stmdev_ctx_t dev_ctx;
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
dev_ctx.handle = &hi2c1;
MX_I2C1_Init();
...
lis2dw12_device_id_get(&dev_ctx, &whoamI);
if (whoamI != LIS2DW12_ID){
// Device not found
}
...
}
Furthermore when I use HAL_I2C_IsDeviceReady it seems to identify the device.
if(HAL_I2C_IsDeviceReady(&hi2c1, LIS2DW12_I2C_ADD_L,1,1000) == HAL_OK){
// It enters here correctly
debugPrintln(&huart2, "Device Is Ready");
}
It proves that the device is correctly connected.
I would appreciate any help.
Best Regards
Solved! Go to Solution.
2020-04-18 05:51 PM
I solved my problem. The problem was in read function. The right way is:
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len) {
HAL_I2C_Mem_Read(handle, LIS2DW12_I2C_ADD_L, reg, I2C_MEMADD_SIZE_8BIT,
bufp, len, 1000);
return 0;
}
Thank you for help
2020-04-17 01:41 AM
Hi @Community member , did you place the pull-up resistors on I2C SDA and SCL lines? You can also check if you structured well your project by checking the STM32CubeL4 function package examples for Nucelo-L433RC (folder \Projects\NUCLEO-L433RC-P) from MCU side, and the X-CUBE-MEMS1 function pack (folder \Projects\STM32L476RG-Nucleo\Examples\IKS01A3), from LIS2DW12 MEMS + STM32L4 family side. Regards
2020-04-17 08:15 AM
Thank you for the response,
Yes I already tried with pull up resistors and the result it's exactly the same. I was wondering if I have to initialize device in some way. But following the example in Driver's example it seems that nothing is initialized.
2020-04-18 05:51 PM
I solved my problem. The problem was in read function. The right way is:
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len) {
HAL_I2C_Mem_Read(handle, LIS2DW12_I2C_ADD_L, reg, I2C_MEMADD_SIZE_8BIT,
bufp, len, 1000);
return 0;
}
Thank you for help