AnsweredAssumed Answered

STM8L, I2C random infinite loop on 2nd I2C peripheral

Question asked by pietroforte.angelo on Nov 16, 2016
I've narrowed the issue down to the program getting stuck in a while statement indefinitely.  Per the attached file, it is looping indefinitely at line 361.  Nicolas Fillon said I needed to implement some reliability code into the I2C polling, similar to that shown with respect to lines 169-176 of the attached.  However, I'm a bit confused as to how to go about doing that since if I understand correctly, the reliability code needs to return a ERROR or SUCCESS, as per the ErrorStatus function of line 152.  Unfortunately, my function is LM33_WriteReg, which starts at line 354, and is not set up to return ERROR or SUCCESS.  A stm8_eval_i2c_psensor.c was developed out of the nearly identical stm8_eval_i2c_tsensor.c for when the 2nd I2C peripheral.  There are times that the code doesn't get stuck in an infinite loop at line 361, but it gets stuck plenty enough that I've decided to cease all other development until the issue can be resolved.

Interestingly, even though the psensor code is so similar to the tsensor code, I never get stuck in an infinite loop at the equivalent line of the stm8_eval_i2c_tsensor.c code.  The main.c program works such that I load registers first into the LM33 peripheral and then into an LM75 peripheral.  If the LM33 peripheral doesn't hang, then the LM75 never hangs, so we need to focus on the LM33 psensor code.  

Lastly, when the code decides to loop indefinitely at line 361, the I2C1_CR2 register shows a value of 0x05, whereas usually its' value is 0x04.

By the way, when the code gets stuck in the while loop indefinitely, the GenerateSTART doesn't occur on the bus.

Outcomes