Serial port Arduino无法正确地从串行中断例程返回
我的程序在循环中什么也不做。我为串行端口(USART)设置了一个中断。当数据到来时,是的,它工作并切换LED。但它只做一次。一旦它进入了中断,它就不会回到它停止的地方 我的密码在这里Serial port Arduino无法正确地从串行中断例程返回,serial-port,arduino,interrupt,Serial Port,Arduino,Interrupt,我的程序在循环中什么也不做。我为串行端口(USART)设置了一个中断。当数据到来时,是的,它工作并切换LED。但它只做一次。一旦它进入了中断,它就不会回到它停止的地方 我的密码在这里 #include <avr/interrupt.h> #include <avr/io.h> volatile int state_Led = LOW; void setup() { pinMode(8, OUTPUT); UBRR0H = 0; // Lo
#include <avr/interrupt.h>
#include <avr/io.h>
volatile int state_Led = LOW;
void setup()
{
pinMode(8, OUTPUT);
UBRR0H = 0; // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
UBRR0L = 8; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UCSR0B |= (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0); // Turn on the transmission, reception, and Receive interrupt
interrupts();
}
void loop()
{
digitalWrite(8, state_Led);
}
ISR(USART_RX_vect)
{
state_Led = !state_Led;
}
#包括
#包括
易失性int状态_Led=低;
无效设置()
{
pinMode(8,输出);
UBRR0H=0;//将波特率值的高8位加载到UBRR寄存器的高字节中
UBRR0L=8;//将波特率值的低8位加载到UBRR寄存器的低字节中
UCSR0B |=(1USART接收中断在准备中断以从ISR返回重新启用之前,还需要读取接收到的数据寄存器
请尝试以下操作:
ISR(USART_RX_vect)
{
unsigned char c = UDR0; // clear the USART interrupt
// or UDRn, UDR0, UDR1, etc...
state_Led = !state_Led;
}
非常感谢您的回答。这正是问题所在。我想这会使空支票符号变为绿色,对吗?我做到了。再次感谢。