我正在使用Atmega169/AVR Butterfly的UART传输到另一块板,波特率为56700,无奇偶校验,1个停止位,无流量控制。振荡器运行频率为7,3768 The (已选中)。我可以成功传输数据(用其他板和PC/超级终端检查),但不能接收任何数据-运行调试器时,配置位都设置正确,但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;
}发布于 2012-04-19 20:59:51
好的,我用示波器测试了连接,电路板上的RXD线断了,切换了电路板,现在它工作了,所以上面的代码是有效的!
https://stackoverflow.com/questions/10212853
复制相似问题