cancel
Showing results for 
Search instead for 
Did you mean: 

I2C error handle in cosmic compiler.

MGarb.5
Associate II

Hi there.

I´m using a STM8S207 with cosmic compiler.

I am reading and writing a 24L64 eeprom thru i2C and everthis is working well.

But i want to put protection in the routines to avoid lock the program in case of fail of a write or read command.

i found a text with this information:

 @note 

     For error management, it is advised to use the following functions:

      - I2C_ITConfig() to configure and enable the error interrupts (I2C_IT_ERR).

      - I2Cx_ER_IRQHandler() which is called when the error interrupt occurs.

       Where x is the peripheral instance (I2C1, I2C2 ...)

      - I2C_GetFlagStatus() or I2C_GetITStatus() to be called into the 

       I2Cx_ER_IRQHandler() function in order to determine which error occurred.

      - I2C_ClearFlag() or I2C_ClearITPendingBit() and/or I2C_SoftwareResetCmd() 

       and/or I2C_GenerateStop() in order to clear the error flag and source 

       and return to correct communication status.

Questions:

Where is this I2C_ITConfig() function in stm8 library?

How i handle the error message? I am a little lost in this part..

Sincerelly

Marcelo

2 REPLIES 2

>>How i handle the error message? I am a little lost in this part..

Notionally I suppose if you flag the failing in the interrupt, you signal this via a variable/flag that your code that's waiting / blocking for the function to complete breaks out of it's while() loop, and you make a determination to propagate the error, or decide if you want to retry the interaction, and how many times, etc.

Perhaps determine if you need to reset the device you're communicating with, or the I2C peripheral on the MCU.

You should perhaps map out the type(s) of failures you expect to see, or are seeing, and the means / methods by which you might respond or recover from those, or give up.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MGarb.5
Associate II

Hi Tesla, thanks for the answer!

I found a example in the read routine of eeprom:

time_out= 5000;																					while((I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)) && (--time_out));//espera desocupar
	if(!time_out) return (something);	

In this case, if the memory doesn´t respond, after 5000 retries the time out goes to 0 and i can return an error message.

But the return way is the same of return of a eeprom adress data (0-255 range), how i can separate a valid data from an error information?