|
#include <avr/io.h>
#include <os.h>
#define REV_BUF_LEN 10
volatile unsigned char revBuf[REV_BUF_LEN];
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[revBufCount] = revOneByte;
revBufCount++;
OSH_wait();
if(revBufCount >= REV_BUF_LEN)
{
revBufCount = REV_BUF_LEN-1;
}
AtomicEnd(atomicState);
}
整个系统已经实现了串口数据发送,在串口调试助手可以看到数据不停的发送过来显示。但是通过给单片机发送数据时,单步调试可以看到发送数据存储在了数组中,而要发送一串十六进制数时,只有前三个字节正常显示,其余的都不正常。
还有,如果不采用单步调试,明明触发了接收中断,但是暂停后,数组里仍然没有数据,全是00。
这个问题已经困扰了好久了,始终找不到解决方法。
真诚的希望马老师指点下,谢谢! |
阿莫论坛20周年了!感谢大家的支持与爱护!!
月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!
|