I2C Receive getting extra invalid byte using HAL
Posted on May 31, 2017 at 19:33
I am using an stm32f030x8. I am using the HAL. Normal operation I can use I2C reads/writes with no problems; however, I can occasionally have errors in the receive data when more activity is taking place on the MCU. I scoped the lines and the bytes on the line are correct/as expected. While step debugging, I can see that the data seemingly gets shifted by a byte when this occurs (i.e. byte 0 in the receive array is some garbage value that was not actually on the bus (verified from scoping the lines), byte 1, 2 etc are the expected data.
Things to note: using synchronous reads here, interrupts are not in play. this system uses single priority interrupts (no nesting)
Things I have verified:
- The actual data on the physical line is correct (scope + logic analyzer verifies this)
- I verified that the pointer address for the buffer being passed in does not get changed (rules out memory corruption of that pointer)
- Verified that the bad data byte is being read out of the rx hw register. The following line shows that RXDR is holding the 'garbage' byte during step debug: (*hi2c->pBuffPtr++) = hi2c->Instance->RXDR;
- Verified that worse case memory does not corrupt stack/heap (this was my initial thought since we are pretty close to utilizing the full RAM capabilities of this device). We have ~800 bytes to spare between heap/stack region in worse case scenario.♯
