AnsweredAssumed Answered

I2C interrupt handler with STM32F2xx Standard Peripheral Library

Question asked by peelo.frank on Jan 15, 2014
Latest reply on Feb 4, 2014 by peelo.frank
Hi

I am writing an I2C interrupt handler for the STM32F207 and am using the Standard Peripheral Library.

The problem I currently have is how to set up a NAK when receiving 1 byte from an I2C slave. According to the reference manual, RM0033, "In case a single byte has to be received, the Acknowledge disable is made during EV6 (before ADDR flag is cleared) and the STOP condition generation is made after EV6" (section 23.3.3, p585, "Master receiver").

But the standard peripheral library documentation describes using I2C_CheckEvent(), I2C_GetLastEvent() or I2C_GetFlagStatus() (UM1061, p313, "I2C State Monitoring Functions"), which, unless I've got something wrong, will all clear the ADDR flag before you even get to see what the event was. They read SR1 and SR2, and RM0033 says "This bit is cleared by software reading SR1 register followed reading SR2" (I assume there was supposed to be a "by" after "followed").

Is the standard peripheral library not supposed to be used in an interrupt handler? Or is GetLastEvent() not the right way to determine the cause of I2C2_EV_IRQHandler() being called?

Outcomes