UART interrupt received data exceeds the buffer size
Posted: Wed Mar 18, 2020 8:00 am
Hi, I use UART(6) of pyb1.1,Firmware version is V1.11.
The code is as follows
#------------------------------------------------------------------
from pyb import UART,Switch
WT901_ISR_flag = 0
key = Switch()
def WT901_ISR(t):
global WT901_ISR_flag
WT901_ISR_flag = 1
WT901 = UART(6,9600)
WT901.init(baudrate=9600, bits=8, parity=None, stop=1, timeout=10, read_buf_len=64)
WT901.irq(trigger = WT901.IRQ_RXIDLE, handler = WT901_ISR)
while 1:
if WT901_ISR_flag == 1:
val = WT901.read()
WT901_ISR_flag = 0
print(val)
#------------------------------------------------------------------
When the data received by UART (6) exceeds the number of bits in the receive buffer(read_buf_len=64), the data received after the second time is empty.
I don't know how to deal with it. When UART (6) doesn't use interrupts, it can work normally even if the received data exceeds the receiving buffer, but the data still hasn't been taken away (it doesn't matter). It's mainly to find out how the use of interrupts can cause such problems. Thank you for checking
The code is as follows
#------------------------------------------------------------------
from pyb import UART,Switch
WT901_ISR_flag = 0
key = Switch()
def WT901_ISR(t):
global WT901_ISR_flag
WT901_ISR_flag = 1
WT901 = UART(6,9600)
WT901.init(baudrate=9600, bits=8, parity=None, stop=1, timeout=10, read_buf_len=64)
WT901.irq(trigger = WT901.IRQ_RXIDLE, handler = WT901_ISR)
while 1:
if WT901_ISR_flag == 1:
val = WT901.read()
WT901_ISR_flag = 0
print(val)
#------------------------------------------------------------------
When the data received by UART (6) exceeds the number of bits in the receive buffer(read_buf_len=64), the data received after the second time is empty.
I don't know how to deal with it. When UART (6) doesn't use interrupts, it can work normally even if the received data exceeds the receiving buffer, but the data still hasn't been taken away (it doesn't matter). It's mainly to find out how the use of interrupts can cause such problems. Thank you for checking