繁体   English   中英

AVR ATMEGA328p BAUD速率错误/无串行连接

[英]AVR ATMEGA328p BAUD Rate Error / No Serial Connection

我无法运行串行连接来测试我的AVR芯片。 我目前认为这是因为F_CPU值,但是我不确定100%。 将程序加载到芯片上时,会出现为#error Systematischer Fehler der Baudrate größer 1%定义的手动错误。 我现在不知道从哪里开始寻找错误。 连接时,我的串行终端的控制台不显示任何输出。

我创建了一个最初加载的配置文件:

configGl​​obal.h

#ifndef F_CPU
#warning "F_CPU not yet defined, and will be set to 1MHz"
#define F_CPU 1000000UL
#endif

USART.c

#include "configGlobal.h"
#include <avr/io.h>
#include "USART.h"

#define BAUD 9600UL
#define BAUDRATE ((F_CPU) / (BAUD * 8UL) - 1) // set baud rate value for UBRR

void initUSART(void) {
    // Requires BAUD
    UBRR0H = (BAUDRATE >> 8) // Shift regisgter right by 8 bits to get upper 8 bits
    UBRR0L = BAUDRATE;
    UCSR0A |= (1 << U2X0);

    // Enable USART
    UCSR0B = (1 << TXEN0) | (1 << RXEN0); // Activate TX RX
    UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); // 8 data bits, 1 stop bit
}

main.c

#include "configGlobal.h"
#include <avr/io.h>
#include <util/delay.h>
#include "USART.h"

int main(void) {

  char serialCharacter;

  // --- INITS --- //
  DDRB = 0xff;

  // Set up LED for output
  initUSART();
  printString("Hello World!\r\n");

  return 0;
}

欠款的输出

AVR Development Stack
Get input main.c file...
In file included from main.c:1:0:
configGlobal.h:2:2: warning: #warning "F_CPU not yet defined, and will be set to 1MHz" [-Wcpp]
 #warning "F_CPU not yet defined, and will be set to 1MHz"
  ^
In file included from USART.c:1:0:
configGlobal.h:2:2: warning: #warning "F_CPU not yet defined, and will be set to 1MHz" [-Wcpp]
 #warning "F_CPU not yet defined, and will be set to 1MHz"
  ^
In file included from /usr/local/CrossPack-AVR-20131216/avr/include/avr/io.h:99:0,
                 from USART.c:2:
USART.c: In function 'initUSART':
USART.c:10:2: error: called object is not a function or function pointer
  UBRR0L = BAUDRATE;
  ^
Convert elf file to hex...
Uploading data to microcontroller...

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: Expected signature for ATmega328 is 1E 95 14
         Double check chip, or use -F to override this check.

avrdude done.  Thank you.

编译器错误是由于缺少“;” 在USART.c中(第10行)。 如果不确定可用的波特率,可以在以下位置检查波特率的兼容性: http : //wormfood.net/avrbaudcalc.php

请记住,将AVR的内部RC振荡器用作时钟源可能会导致UART不稳定,因为频率不完全是8MHz(如果CKDIV8 = 1,则为1MHz)。

avrdude-log的底部表明设备设置不正确。 您确定已连接ATmega328而不是ATmega328P吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM