2019-08-28 03:08 AM
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);
}
2019-09-08 12:18 PM
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.
2019-09-09 02:39 AM
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.
2019-09-09 07:03 AM
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!
2020-05-26 06:21 AM
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