This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART RX interrupt

Hi, I am using the STR912FA and I am trying to implement the UART communication using interrupts. I am using the interrupt only for receiving data, but for some reason I never get an interrupt when writing a character in the hyperterminal ...
The transmition works ok using the printf to the hyperterminal.
Does someone see something wrong in my code?
Thanks a lot!

This is my UART initialization:

// UART  Module
  UART_InitStructure.UART_WordLength = UART_WordLength_8D;
  UART_InitStructure.UART_StopBits = UART_StopBits_1;
  UART_InitStructure.UART_Parity = UART_Parity_No ;
  UART_InitStructure.UART_BaudRate = 115200;
  UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
  UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
  UART_InitStructure.UART_FIFO = UART_FIFO_Disable;
  UART_DeInit(UART0);
  UART_Init(UART0, &UART_InitStructure);
  UART_Cmd(UART0, ENABLE);
  UART_ITConfig(UART0, UART_IT_Receive, ENABLE);
  VIC_DeInit();
  VIC_Config(UART0_ITLine, VIC_IRQ, 2);
  VIC_ITCmd(UART0_ITLine, ENABLE);

This is the interrupt (That I never get):

void UART0_IRQHandler(void)
{
 /*clear receive interrupt flag*/
  UART_ClearITPendingBit(UART0, UART_IT_Receive);
  //UART_ClearITPendingBit(UART0, UART_IT_Transmit);
  /*send back the received character*/
  while(UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) != RESET);
  UART_SendData(UART0, UART_ReceiveData(UART0));
}

This is my byte transmition (works):

int MyLowLevelPutchar(int x)
{
    UART_SendData(UART0, x);
    while(UART_GetFlagStatus(UART0, UART_FLAG_TxFIFOFull) == SET);

  return x;
}

Parents
  • You changed your code in an incorrect way.

    You should have an empty loop while the FIFO is full (just like the original code had) but _before_ the insert.

    First after you end this loop should you do the insert. Now you changed the code to do the insert inside a conditional.

        // Wait until room for at least one more character in FIFO
        while(UART_GetFlagStatus(UART0,UART_FLAG_TxFIFOFull) == SET) ;
        // Insert character in FIFO and return.
        UART_SendData(UART0, x);
        return x;
    

Reply
  • You changed your code in an incorrect way.

    You should have an empty loop while the FIFO is full (just like the original code had) but _before_ the insert.

    First after you end this loop should you do the insert. Now you changed the code to do the insert inside a conditional.

        // Wait until room for at least one more character in FIFO
        while(UART_GetFlagStatus(UART0,UART_FLAG_TxFIFOFull) == SET) ;
        // Insert character in FIFO and return.
        UART_SendData(UART0, x);
        return x;
    

Children
No data