Author Topic: Does this code need interrupts disabled?  (Read 35469 times)

0 Members and 2 Guests are viewing this topic.

Offline wek

  • Frequent Contributor
  • **
  • Posts: 591
  • Country: sk
Re: Does this code need interrupts disabled?
« Reply #150 on: February 22, 2023, 06:30:37 pm »
> One is always torn...

The best thing is to write a minimal but complete compilable code exhibiting the problem, and post it as a zip in its entirety. Then post only relevant portions in the text.

For example:

> void serial_transmit_irq_handler(UART_HandleTypeDef *huart, uint8_t port)

Whatizit? How is it called, in what context, what is preceding and succeeding calling this function, etc.etc.

---

> UART_IT_TXE

As I've said, stop using it.

Use symbols from the CMSIS-mandated device header when accessing/talking about registers.

Use any random Cube/HAL gobbledygook when using the Cube/HAL functions, exclusively.

---

> if (serial_transmit_buffer_tx_index[port] == serial_transmit_buffer_put_index[port])

does not guarantee that there is nothing in the shift register, so clearing USART_CR1.TXEIE does not guarantee that either.

As NorthGuy says too, guard the attempt to transmit by USART_CR1.TCIE (and again, don't use UART_IT_TC etc.)

Or, better, don't transmit from main at all, as soon as you set USART_CR1.TXEIE and the transmitter buffer is empty, the interrupt will fire and perform the transmission.

JW


 
The following users thanked this post: peter-h

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6115
  • Country: gb
  • Doing electronics since the 1960s...
Re: Does this code need interrupts disabled?
« Reply #151 on: February 22, 2023, 06:52:05 pm »
Quote
don't transmit from main at all, as soon as you set USART_CR1.TXEIE and the transmitter buffer is empty, the interrupt will fire and perform the transmission.

Interesting. On most UARTs you get the TX interrupt only when the TX becomes empty.

Maybe that is the whole problem. I don't need to load the byte into the UART at all. I just need to enable TXE interrupt.

Bloody hell. It works!

Astonishing nobody has picked that up before. Such a simple thing. But as I say most UARTs don't work that way.
« Last Edit: February 22, 2023, 07:18:09 pm by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->