2024-09-19 01:45 AM
Hi,
I was just wondering if someone could spot why my code could be failing when my CheckMBMode function is being called in my main loop. I am successfully opening a security session before reading and writing to the MB Mode register so I am unsure what I am doing wrong.
Code:
#define ST25DV_I2C_SYST_ADDRESS 0xAE
#define MB_MODE_ADDRESS 0x000D // MB_MODE register address (for enabling FTM)
// Function to read and check the status of MB_MODE (FTM status)
HAL_StatusTypeDef CheckMBMode(uint8_t *reg_value) {
// Read the MB_MODE register (1 byte, 8-bit register)
return HAL_I2C_Mem_Read(&hi2c1, ST25DV_I2C_SYST_ADDRESS, MB_MODE_ADDRESS, I2C_MEMADD_SIZE_16BIT, reg_value, 1, HAL_MAX_DELAY);
}
Thanks.
Solved! Go to Solution.
2024-09-19 05:30 PM
Changing the I2C_MEMADD_SIZE_8BIT to 16BIT seemed to fix the error.
Both MB_MODE and Dynamic Ctrl are being set and read correctly now.
2024-09-19 02:55 AM
Hello,
Nothing looks wrong in your code.
Do you have any debug trace to share, or wo you know at which Byte your i2C command is NACK'ed ?
Also, are the other I2C command working fine?
Best regards.
2024-09-19 03:12 AM
I have found that the function doesn't get caught if I do not call my enable Dynamic Mailbox function.
If this function is called the following occurs.
In I2C Mem Read it goes to an error handler at the highlighted line:
This is the error handler that it gets stuck in:
My set MB_MODE function does not seem to be working as the check function is not returning 0x01.
Thanks again.
2024-09-19 05:30 PM
Changing the I2C_MEMADD_SIZE_8BIT to 16BIT seemed to fix the error.
Both MB_MODE and Dynamic Ctrl are being set and read correctly now.