cancel
Showing results for 
Search instead for 
Did you mean: 

How to force I2C-NACK in slave receiver by using NBYTES?

Mr_M_from_G
Senior II

Hi everyone,

I am using STM32G070 Nucleo board and work with I2C and use DMA to reload TXDR or read out RXDR. I built up a master that shall also be able to receive from other masters. Everything works fine so far. Now I want to limit the number of bytes clocked in by the other master and from reading the data sheet I assumed this is done by setting NBYTES to the desired value, making the peripheral send NACK when the number of bytes is reached. It works this way with master receiver and it works in a corresponding way with slave transmitter (there sending only FF after NBYTES are out). But it does not work with slave receiver. I still get all the bytes sent into my memory risking a buffer overflow.

Am I missing something?

Thanks for any help

Martin

2 REPLIES 2
PR.10
Associate III

dma will stop when full, it disables automatically and wont overflow memory. note that It will not consume any bytes from i2c rx reg then

PR.10
Associate III

if you set number of bytes to NBYTES and enable TCR interrupt then you can inside the TCR call set NACK bit. Master should react to that by generating STOP. Then the slave is released.

I does work for me, but I use my own driver now. The HAL driver got stuck way too often.