Skip to main content
Visitor II
August 28, 2019
Question

STM8S UART TX Interrupt Problem

  • August 28, 2019
  • 4 replies
  • 2390 views

Hello to everyone, 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, tried to develop same code. However, I got still zero.

I took interrupt vector function from STM8 examples. Where is the 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);
}

    This topic has been closed for replies.

    4 replies

    Visitor II
    September 8, 2019

    Hi!

    Did you enable the master clock for the USAR1 module? I don't see it in your code.

    If not, you need to enable it in CLK_PCKENR register.

    Visitor II
    September 9, 2019

    Hi Cristian, thanks for your reply. I have solved my problem. I think it is related about my complier. When I change it to IAR, all problem is gone. Now, I can send and receive a message via UART.

    Visitor II
    September 9, 2019

    Hi Murat!

    I'm glad you solved your problem, but, if I were you, I would ask myself what was really wrong and why it did not work with the other compiler.

    Than, changing the compiler every time you encounter an error is also not the right way.

    IAR might be doing some background work for you, like initialization and settings for peripherals, that was not done with the other compiler. Knowing this stuff will help you a lot in the future.

    Goodbyte!

    Visitor II
    May 26, 2020

    The IRQ is appearing once the UART has sent something. Since you not seem to send anything the IRQ is not triggered.

    Check RM0016 page 363