c - AVR Butterfly UART - 无法接收数据

标签 c interrupt avr uart

我正在使用 Atmega169/AVR Butterfly 的 UART 传输到另一 block 板,波特率 56700,无奇偶校验,1 个停止位,无流量控制。振荡器运行在 7,3768Mhz(已检查)。我可以成功传输数据(通过其他板和 PC/HyperTerminal 检查),但没有收到任何数据 - 当运行调试器时,配置位都设置正确,但 RXC 始终为假 - 我还检查了我是否可以发送数据到我自己(将 TXD 连接到 RXD 并接地),但没有成功。 (尝试使用 ISR 和轮询) 下面是代码的相关部分,我希望你能处理它——PORTB 被用作示波器测试的输出(我知道我可以只使用一个引脚,但现在 PORTB 上没有其他东西):

int main(void){
OSCCAL_Calibrate();       // calibrate the internal oscillator
int UBRR_VAL  = ((F_CPU)/(BAUD*16)-1);
UART_Init(UBRR_VAL);
DDRB |= 0xFF;
PORTB = 0;
testCharSend();

while(1);
return 0;
}

void testCharSend()
{
char i = 'x';
while(1){       
    Uart_Tx(i);
}
}

void UART_Init(unsigned int baudrate)
{
    // Set baud rate
    UBRRH = (unsigned char)(baudrate>>8);
    UBRRL = (unsigned char)baudrate;

    UCSRA = 0;

    // Enable receiver and transmitter
    UCSRB = (1<<RXEN)|(1<<TXEN);

    // Async. mode, 8bit, No parity, 1 stop bit (like CC2540)
    UCSRC = (0<<UMSEL)|(0<<UPM0)|(0<<USBS)|(3<<UCSZ0)|(0<<UCPOL);

// enable receive interrupt
UCSRB |= (1<<RXCIE);

// flush UART
UART_Flush();
}

void UART_Flush( void )
{
unsigned char  dummy;
while ( UCSRA & (1<<RXC) ) dummy = UDR;
}

void Uart_Tx(char data)
{
    while (!(UCSRA & (1<<UDRE)));
    UDR = data;
}

ISR (USART0_RX_vect)
{
    PORTB ^= 0xFF;
char c = UDR;
}

最佳答案

好的,我用示波器测试了连接,板子上的RXD线坏了,换了板子现在可以工作了,所以上面的代码是有效的!

关于c - AVR Butterfly UART - 无法接收数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10212853/

相关文章:

gcc - AVR 内联汇编 : registers to variables?

programming-languages - 针对 Arduino/AVR 的编程语言

c - 在 C 中设置静态分配结构的宏

javascript - 为 asm.js 编写优化的 JS

c++ - 编译错误。如何使用 lex/yacc 解析变量名?

c++ - Windows Mobile/C : Wait until variable changes

java - Java 中的 Thread.interrupt() 和 Thread.currentThread.interrupt() 有什么区别?

operating-system - 有人可以帮我解决一些我无法掌握的操作系统概念 - 重新中断

c - 如何在LCD上写入浮点值?

c - 来自 gpio int 处理程序的 i2c 传输在 imx6sx cortex m4 侧失败