AlexanderMandera / arduino-wch32v003

Arduino Core for CH32V003 RISC-V microcontroller
GNU Lesser General Public License v2.1
154 stars 18 forks source link

HardwareSerial disable USART interrupt #22

Open sintrb opened 4 months ago

sintrb commented 4 months ago

cores/arduino/api/HardwareSerial.cpp

when "rxBufferTail == rxBufferHead" USART interrupt will be disable. What time to enable USART interrupt. If not no way to read data. make a ring buff is more useful.

extern "C" void USART1_IRQHandler(void) {
    if(USART1->STATR & USART_FLAG_RXNE) {
        // Write into buffer
        rxBuffer[rxBufferTail] = USART1->DATAR & (uint16_t)0x01FF;

        rxBufferTail = (rxBufferTail + 1) % RX_BUFFER_SIZE;

        if(rxBufferTail == rxBufferHead) {
            // Buffer empty, disable USART interrupt
            USART1->CTLR1 &= ~USART_FLAG_RXNE;  // here
            return;
        }
    }
}