0

Thanks to everyone who gives an answer. But the problem is related to the compiler. I used Cosmos and STVD, it does not bind the interrupt function. When I immigrate the project to IAR, The problem is solved.

I am dealing with STM8S103F3P6 IC. I try to send a message using TX interrupt but I have never succeeded.

I have checked the example of the UART interrupt. Also, I tried to develop the same code. However, I got still zero. I took the interrupt vector function from STM8 examples. Where is my mistake? How can I figure out?

Here my init, main, and interrupt vector function;

void init_handler(void){
      CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
      UART1_DeInit();
      UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
      UART1_ITConfig(UART1_IT_TXE,ENABLE);
  enableInterrupts();
      UART1_Cmd(ENABLE);
}


main(){
      init_handler();
      while(1);
}

INTERRUPT_HANDLER(UART1_TX_IRQHandler, 17){
      /* In order to detect unexpected events during development,
      it is recommended to set a breakpoint on the following instruction.
      */
     UART1_SendData8('a');
     while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
 }

It sends nothing. I do not have any logic analyzer, I have only checked using terminal applications.

2 Answers 2

3

You asked where your mistake is: that's hard to tell if you use library functions that mask the usage of peripheral configuration registers and flags by making them "readable". If you don't have a logic analyzer, pin debugging helps most of the time (e.g. toggle a GPIO when entering the ISR).

My advise is to look at the actual register manipulations and to compare those with the descriptions in the STM8S Reference Manual (even if it doesn't provide concise guidance on how to initialize, start, spin down and end a transmission).

In order to make that a little easier, I'd like to share what I learned about using a UART ISR:

Sending the contents of a buffer with UART TXE and TC interrupt events turns out not to work like in e.g. MCS51: most of it has to be done with the interrupt enable flags TIEN and TCIEN in UART_CR2.

This is what worked for me:

  • both TIEN and TCIEN should be normally disabled
  • after setting up buffers and pointers, enable TIEN to start a transmission
  • in the ISR, during the transmission, writing to UART_DR clears the interrupt event
  • in the ISR, when the buffer is empty, disable TIEN and enable TCIEN to spin down the ISR chain
  • in the ISR, read UART_SR to check if TC is set. If that's the case, clear TCIEN

The advantage of this procedure is that media access control, e.g. for RS485, can be done in the last step of the chain.

An example in STM8 eForth is here.

Sign up to request clarification or add additional context in comments.

3 Comments

Is enabling the TCIEN really necessary when the buffer is empty? After all, you just get another interrupt where you disable it again. I just disable TIEN when the buffer is empty and it seems to work just fine.
It depends if you need to know just when the transmission is complete. In the case of RS485 media access control it's necessary. In other cases disabling TIEN when the buffer is empty, as you describe it, should be sufficient.
Thanks for the clarification. Since i only have two devices communicating, no media access control is necessary and i will disregard of the Transmission Complete (TC) interrupt (enabled with the TCIEN bit).
1

SPL and opinions about that have nothing to do with the problem. As the SPL code is open sourced you can have a look and even copy it.

UART1_IT_TXE occurs after the UART has transmitted something. Since you don't send anything (yet) the IRQ is not triggered.

You can send a series of characters using the UART1_IT_TXE IRQ by sending the first character using the UART1_SendData and then let the IRQ handle the remaining ones.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.