2020-01-30 12:51 PM
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.
2020-01-30 04:38 PM
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
2020-01-31 03:15 AM
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.
2020-01-31 03:39 AM
> 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
2020-03-25 09:46 AM
For information, you can read here what I had to do to have a library that works.
2020-03-25 11:23 AM
Thanks for the writeup.
Jan
2023-02-27 02:12 PM
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.