1

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.

SamGibson
  • 17,231
  • 5
  • 37
  • 58
andreahmed
  • 23
  • 7

3 Answers3

2

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.

1

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)

SamGibson
  • 17,231
  • 5
  • 37
  • 58
Mukesh
  • 80
  • 1
  • 6
0

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.

Justme
  • 127,425
  • 3
  • 97
  • 261
  • There is no generation of a NACK on STM32F407.. please double check and you will see that – andreahmed May 17 '19 at 07: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 '19 at 09:36