I've written my software to follow the sequence in the RA4M1 manual, figure 28.10, and I want to use the TEI interrupt to switch off the RS485 line driver when the data has been sent.
I negate TXI and enable TEI immediately after sending the last byte to TDR.
It works perfectly, apart from one thing - it generates the TEI interrupt twice, even though I negate TEIE in the interrupt service routine.
(Running the ISR twice doesn't affect the operation of the program, but wouldn't it be tidier if if didn't?)
Hello Ian,
From your comments, I can understand that you don't use any FSP driver to configure the SCI channel, but you have created your own software.
I am asking it, because some FSP ISR have already been configured to implement the flowchart below:
Let's suppose that you have created your own code. Do you set the TIE to 0 and TEIE bit to 1 when the TEI interrupt is in use after the last data transmission?
Regards,
AL_Renesas
Yes. That is exactly what it does. Does TIE need to be reset before TEIE is set, because if I put it two statements, the compiler is likely to combine it into a single statement which sets/resets them simultaneously.
Find below, how sci_uart_txi_isr (FSP uart driver) handles TEIE, TIE after all data has been transmitted:
So that makes absolutely sure that both flags are updated simultaneously. I'll try that and see what happens.
It still interrupts twice.
What should the TEIE handler do? Apart from turning off the enable to the RS485 driver, all it does is negates TE, TIE and TEIE.
Does the FSP version also interrupt twice?
Can you please attach your project here or on private message?
I found the TEI interrupt handler in FSP, and checked it against mine.
I always clear the flag
R_ICU->IELSR[2] &= ~(1U << 16);
at the beginning of the service routine, but FSP clears it at the end (I don't know whether that applies to every interrupt service routine in FSP or just this one.
Obviously, the act of clearing TEIE, TIE and TE results in an undocumented TEI interrupt being generated, which is then cleared by clearing IELSR at the END of the ISR.