I'm trying to resolve this issue for some time now but no luck. I'll state the short form of the firmware workflow.
Behind the simple task-scheduler (lowest ISR priority) there is a constantly running SPWM generator (48kHz) and a ADC (48kHz) (2ch PDB driven). Both are using (high priority) ISR's to set/read parameters.
I2C is connected to a 4x20 character LCD. I2C is clocked at 400kHz. I2C is also used as a non-blocking process with a state machine in ISR to service the ADDRESS-COMMAND-DATA sequence. Address and Command bytes never change.
Every 1ms there is a function call to send a char to a LCD. When to counter runs to 80, whole thing starts again. To start a transfer there is a dedicated function StartMaster(...); that prepares the data to be sent in a software TX buffer. Software TX buffer later fills the I2C periphery hardware Tx buffer.
After a call of the function (I2C bus must be IDLE first), ADDRESS is sent to the LCD. On ACK, ISR send the COMMAND, and on second ACK, ISR sends the DATA byte. STOP is generated after the last ACK.
Sometimes, very irregularly and hard to connect with other functions, the I2C driver detects FIFO Error Flag. This then blocks the LCD and whole thing freezes until reset.
I would appreciate very much if some one knows the conditions in which this flag is raised (or suggest the workaround). Datasheet is very narrow in describing this phenomena: Detects an attempt to send or receive data without first generating a (repeated) START condition. (Kinetis KE1xF Sub-Family Reference Manual, Rev. 3, 06/2017, Page 1250)
If any additional information's are necessary please do ask. I can even present some code segments if needed.