cancel
Showing results for 
Search instead for 
Did you mean: 

stm32g071 HAL_I2C_Slave_Seq_Transmit_DMA DMA TC flag is set even if one element less than requested was transferred

a34fheuak
Associate II

I am using a stm32g071 as an I2C slave.

Problem is, that I2C_SlaveTxCpltCallback() callback is called even when the master read one byte less than previously configured.

I.e. With RXSIZE = 4 (as in code below),

  • if master reads 1 byte -> ok
  • if master reads 2 bytes -> ok
  • if master reads 3 bytes -> fail. DMA TC flag is set and I2C_SlaveTxCpltCallback is called. This should not be the case, as there were 1 byte less transferred than requested.
  • if master reads 4 bytes -> ok. DMA TC flag is set and I2C_SlaveTxCpltCallback is called

I tested other numbers, and generally the DMA sets the TC flag if N-1 bytes were transferred and the master sends a stop condition (or NACK).

Code excerpt is below. Unfortunately you will need a second device to reproduce this. Could this be a hardware issue?

void I2C_AddrCallback(uint8_t TransferDirection, uint16_t AddrMatchCode)
{
	(void) AddrMatchCode;
 
	if (TransferDirection == I2C_DIRECTION_RECEIVE) {
		HAL_I2C_Slave_Seq_Transmit_DMA(&m_i2c, data, 4, I2C_NEXT_FRAME);
	} else {	// I2C_DIRECTION_TRANSMIT (from master perspective)
                ...
	}
}
 

0 REPLIES 0