1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

Page 849 from revision 18 of STM32F407 Reference Manual RM0090

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

\$\endgroup\$
1
\$\begingroup\$

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.

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

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.

\$\endgroup\$
  • \$\begingroup\$ There is no generation of a NACK on STM32F407.. please double check and you will see that \$\endgroup\$ – andreahmed May 17 at 7:23
  • \$\begingroup\$ 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? \$\endgroup\$ – Justme May 17 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.