Beispiel #1
0
/**
 * @brief IRQ handler for USART2
 */
void USART2_IRQHandler(void) {

  // If transmit buffer empty interrupt
  if(USART_GetITStatus(USART2, USART_IT_TXE) != RESET) {

    uint8_t c;

    if (txCallback) { // if not NULL
      // get data from higher layer using callback
      if (txCallback(&c)) {
        USART_SendData(USART2, c); // Send data
      } else { // if no more data to send disable the transmitter
        USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
      }
    }
  }

  // If RX buffer not empty interrupt
  if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {

    uint8_t c = USART_ReceiveData(USART2); // Get data from UART

    if (rxCallback) { // if not NULL
      rxCallback(c); // send received data to higher layer
    }
  }
}
void BufferedSerial::rxIrq(void)
{
    // read from the peripheral and make sure something is available
    if (serial_readable(&_serial)) {
        _rxbuf = serial_getc(&_serial); // if so load them into a buffer
        if (rxCallback)
        	rxCallback();
    }
}