急!!!请教马老师串口通信中断接收数据无法存储问题!
#include <avr/io.h>#include <os.h>
#define REV_BUF_LEN 10
volatile unsigned char revBuf;
volatile unsigned char revBufCount;
volatile unsigned char revOneByte;
void uartDebug_init()
{
UARTState = UART_IDLE;
dbgBufCount = 0;
revBufCount = 0;
num = 0;
// initialize UART
* (volatile unsigned char *)0x90 = 0; /* UBRR0H = 0 */
* (volatile unsigned char *)(0x09 + 0x20) = 15; /* UBRR0L = 15 */
/* UCSR0A中的U2X0 = 1,即传输速率倍速 */
* (volatile unsigned char *)(0x0B + 0x20) = 1 << 1;
/* UCSR0C中UCSZ1 = 1,UCSZ0 = 1,即传送或接收字符长为8bit */
* (volatile unsigned char *)0x95 = (1 << 2) | (1 << 1);
/* UCSR0B中的RXCIE,TXCIE,RXEN和TXEN都置为1 */
* (volatile unsigned char *)(0x0A + 0x20) = (((1 << 7) | (1 << 6)) | (1 << 4)) | (1 << 3);
}
USRAT接收完成中断
void __attribute((signal)) __vector_18(void)
{
uint8_t atomicState = AtomicStart();
revOneByte = UDR0;
revBuf = revOneByte;
revBufCount++;
OSH_wait();
if(revBufCount >= REV_BUF_LEN)
{
revBufCount = REV_BUF_LEN-1;
}
AtomicEnd(atomicState);
}
整个系统已经实现了串口数据发送,在串口调试助手可以看到数据不停的发送过来显示。但是通过给单片机发送数据时,单步调试可以看到发送数据存储在了数组中,而要发送一串十六进制数时,只有前三个字节正常显示,其余的都不正常。
还有,如果不采用单步调试,明明触发了接收中断,但是暂停后,数组里仍然没有数据,全是00。
这个问题已经困扰了好久了,始终找不到解决方法。
真诚的希望马老师指点下,谢谢! 关于串口中断发送和接收的例子,请参考我编写的教材。
页:
[1]