# How to generate NACK on STM32F407

Is there a way to send a NACK on I2C on STM32F407? There is no way to do that using the HAL, and the datasheet says nothing about it.

I think the following section explains how to generate the NACK. In order to send the NACK signal, the software must clear the ACK bit after reading second last byte. Hope this will help.

(Image source: STM32F407 Reference Manual RM0090, Section 27.3.3, page 849 in revision 18 of the manual)

It is described in the Reference Manual, not in the datasheet. A NACK is sent when the I2C_CR1_ACK bit in I2C->CR1 is set to 0 before receiving the last byte.

HAL should manage this bit automatically according to the transfer size in the HAL_I2C_..._Receive... functions.

• There is no generation of a NACK on STM32F407.. please double check and you will see that. – andreahmed May 17 at 7:10
• @andreahmed Sure, have it your way. But why did you ask it then, if you are so sure it's not possible? – berendi May 17 at 8:20
• I'm just making sure if it's possible or no, can you answer me please ? is it really possible or not at all. – andreahmed May 17 at 8:46
• @berendi the ACK bit of I2C_CR1 controls the sending of an ACK. Not sending an ACK is the same as sending a NACK. – Steve G May 17 at 8:58
• @SteveG +1 you are correct, this doesn't answer my question – andreahmed May 17 at 9:13

Sending a NAK by itself is pointless. The whole purpose of HAL is to handle the protocol for you, will generate a NAK or ACK bit when necessary. And surely the reference manual gives details how to make the I2C peripheral to transmit ACK or NAK after a byte transfer.

• There is no generation of a NACK on STM32F407.. please double check and you will see that – andreahmed May 17 at 7:23
• All my STM32 have been able to respond correctly with a NACK when necessary in all situations where I have needed it, or the I2C protocol would not work at all. What are you trying to do and how? Is your STM32 a slave or master? Are you using the HAL correctly? – Justme May 17 at 9:36