cancel
Showing results for 
Search instead for 
Did you mean: 

Using STM32H743 I2C, with CR2 RELOAD and NBYTES=0 gives TC interrupt instead of TCR.

Nikita91
Lead II

I have to port an existing I2C API to the STM32H743 using the LL drivers. One of the functions must perform the START, issue the address of the slave, then return control. Then another function will send the data.

The fact is that when I initialize the transmission with the slave, I don't yet know the number of bytes to transmit. So the question concerns the transmission of 0 data after the address of the slave.

I use the following code:

	// Set CR2 register
	LL_I2C_HandleTransfer (pI2c,
			slaveAddress,
			LL_I2C_ADDRSLAVE_7BIT,
			0,					// NBYTES
			LL_I2C_MODE_RELOAD,
			LL_I2C_GENERATE_START_WRITE) ;

Using LL_I2C_MODE_RELOAD I expect a TCR interrupt. But I get a TC interrupt, which prevents me from transmitting data.

Is this normal?

Is there a way to get a TCR interrupt under these conditions?

Then I tried to set NBYTES to 1, but it seems that it is not possible to change it later to the real count of data (in the first TXIS interrupt).

Best regards.

6 REPLIES 6

You should perhaps try to start with the NBYTES=1, transmit that one byte after address unconditionally, and then load the required number of bytes minus one into NBYTES for subsequent transfers.

JW

Nikita91
Lead II

Yes.

I did something like that.

Set NBYTES=1 and quit the start function on TXIS interrupt with interrupts disabled (Before writing any data, because at that time I don't know them).

In send data function enable the TXIS interrupt and continue as usual (it is mandatory to have at least 1 byte to transmit, but it is not a serious constraint) .

This allows to implement the API.

But this doesn't explain why I get a TC interrupt while RELOAD is 1.

> But this doesn't explain why I get a TC interrupt while RELOAD is 1.

You mean, when NBYTES=0?

Well, the description of I2C module in RM lacks the required details, but then the description calls for using RELOAD=1 only with NBYTES=255, doesn't it.

JW

Nikita91
Lead II

For information, you can read here what I had to do to have a library that works.

Thanks for the writeup.

Jan

TDJ
Senior III

The question has been answered and the way to do it is to set RELOAD. Only with RELOAD set TCR (transfer complete reload) fires, where NBYTES can be set to a new value. This makes a lot o sense. To get this right, it is critical to study not only RM text but also the corresponding diagrams. It took me two months and just ~500 lines of code to build SMBus driver much better than HAL and test environment using just one Nucleo board with two I2C ports sending data to each other. It definitely was not straight forward.