cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S003F3 UART IRQ freezes mcu

jacdub887
Associate
Posted on November 01, 2016 at 18:44

hello everyone

been playing with that mcu for a while but I cant set up UART IRQ DR(data register) empty

IO pins interrupts work as expected but after setting TIEN in CR2 function enableInterrupts() freezes whole chip and ISR is never hit it just hangs on that function

my code:

ISR(UART1_T_TXE_vector)

{

  PD_ODR ^= 1<<3;

}

int main( void )

{

  UART1_CR1_.M = 1;//9 bit data inc parity bit

  UART1_CR3 |= 0x20;//2 stop bits

    UART1_BRR2 = (u8)0x02;//baud setting 9600 at 16MHz 

  UART1_BRR1 = (u8)0x68;

    UART1_CR1_.PCEN = 1;//parity check enable

    UART1_CR1_.PS = 0;//even parity

  UART1_CR2_.TEN = 1;//TX enable

  //UART1_CR2_.TIEN = 1;//DR empty IRQ enable

  UART1_CR2_.REN = 1;//RX enable

  

  enableInterrupts();

  u8 x = 0;

  u8 buf[10] = { 65,66,67,68,69,70,71,72,73,74 };

  while (x<10)

  {

  UART1_DR = buf[x];   

  while (UART1_SR_.TXE == 0);  

  x++;

  }

anyone have an idea whats wrong? does it require some additional settings?
1 REPLY 1
jackson ward
Associate II
Posted on May 10, 2017 at 21:19

Hello. You probably solved your issue by now, but for anyone else who comes along:

You need to add to interrupt handler routine. You need to reset the bit that signals an interrupt has occurred. Refer to the reference manual. In the UART Status register there are bits which go high for particular interrupts. Figure out which bit went high. Handle that situation. Then reset that bit.

For example, if the interrupt occurred because data is available to be read then you read the data and then reset the RXNE bit. All inside the interrupt handler.