2023-04-27 01:30 PM
I have the IIS2MDC along with LSM6DSL accel / gyro on a board with stm32L451 uC.
Accel / gyro work fine. uC reads status byte then if any axis has new data ready it reads all from temp to accel (0x20-0x2d) in 1 ST hal fn call multi byte read: HAL_I2C_Mem_Read().
IIS2MDC seems to read X-Z fine using same fn that is read X Low to Temp high ( 0x68-0x6F) but the value for 6E-6F is a duplicate of X values (regs 0x68-0x69)
I can read 6 bytes Y to temp and still get the X value for the temp.
If I read X-Z in 1 fn call then temperature in another call, temp reads ok.
I have read each register 0x45 - 0x6f one by one and compared to a read from 0x45-0x6f in 1 bulk read sequence. All matches except temperature or status (if no time for recalc).
temp read alone: 0x6e - 0x1b, 0x6f = 0x00 - these make sense.
temp read as part of axis or previous reads: 0x6e = 7d 0x6f = 0xff.
This is on a board about 75 deg F so 0x001b is about correct.
The IIS2MDC traffic has been verified with a logic analyzer on the I2C bus so it seems to be coming from chip this way NOT mishandling by uC / uC libs.
I don't see anything in data sheet indicating this behaviour. I saw something indicating address increment is unlimited.
cfgs: 0x60 (A) = 0x84, B = 0x12, C = 0x10 ( BDU set BLE is off. ).
offsets set to 0.
no irq's, thing fancy, just update compass outputs at 20 Hz I think it is. It is then polled for status and has values read.
Any ideas??
2023-04-28 03:01 AM
Hi @CClen ,
Welcome to ST Community!
To be sure to read correctly the sensor data in the output registers (68h-6fh) it is recommended to polling the status_reg 67h, and read the data from the output registers (68h-6fh) when the zyxDA bit is 1.
In this way the data read in the output registers has been correctly stored.
If my reply helps you, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster!
2023-04-28 08:24 AM
That is what I was doing.
This is the first time using THIS IC but have 2 others on I2C bus that read fine ... mentioned in first post.
I was reading 68-6f if status & 0x07 was nonzero.
However, it reads 0x0f all the time so that is not it.
It looks that chip can read 6 bytes from 0x68-0x6d in 1 call and 0x6e-0x6f in 1 x 2 byte read call.
If i get 68-6f or 6a-6f 6e-6f is reads as value at 68-69. Also see no change if the auto increment (0x80) is not or'ed into register which is perplexing - I would think per documentation it would NOT increment the register unless that is between successive read commands not read multiple bytes.
I alternated reading 8 data bytes with reading 6 then 2 bytes.
8 always gives temp = x while 6+2 gives correct 3 axis plus correct temp.
Logic analyzer says data matches what the code says is happening and data reported. Can upload LA captures if helpful for verification.
Keil event recorder has logged data which matches the logic analyzer.
It all seems that the chip just won't read axis data + temp in one.
Difficult to think I am first to read it this way and found a problem but all data shows either I missed something on data sheet or multiple reads has odd behavior.
Read function essentially attached. pgHal I2C read fn is simply a cpu abstraction that calls ST hal I2C read mulple fn.
Is there something I am missing???