AVR ATMEGA32A-PU低输出电压

时间:2016-05-15 06:36:29

标签: arduino avr led atmega

我刚开始尝试直接使用AVR,而不是像Arduino Uno那样使用开发板。我所看到的问题是,当我尝试在输出引脚上驱动一堆LED时,其中许多LED读取的电压非常低,低于预期的5V电压。

我正在运行14MHz晶体的代码。我已经将AVR上的保险丝设置为: lfuse:0xFF hfuse:0x89 晶体连接到引脚XTAL1& XTAL2。晶体的每个引脚也通过一个22pF的陶瓷电容连接到GND。

我已经在VCC和GND之间连接了一个.1uF电解电容,而在AVCC和GND之间连接了另一个电解电容,阴极( - )连接到GND端子。我的源终端还有一个10uF的电解电容。

与ATMEGA32A的连接如下: PB0-7:打开 复位:VCC为10K电阻 VCC:5V GND:GND XTAL1:水晶 XTAL2:水晶 PD0-7:LED到GND的510欧姆电阻 PC0-7:LED到GND的510欧姆电阻 AVCC:5V GND:GND AREF:5V(也试过这个OPEN。没有改变) PA0-7:OPEN

PORTD似乎工作正常。我在每个引脚上从AVR到地面的全部4.6V压降。但是,PORTC无法正常工作。当我从C0向上移动时,每个引脚的电压降随着PORTC向上移动而降低。 PC0几乎提供了完整的4.6V。当我到达测量2.2V的C7时,它逐渐减少。

这有什么特别的原因吗?我错过了AVR需要的某种连接吗?我的非常简单的代码和makefile如下所示。

#include <avr/io.h>
void setup();
void setup()
{
  DDRD=0XFF;
  PORTD = 0xff;
  DDRC |= 0XfF;
  PORTC = 0xff;
}
int main()
{
  setup();
  while(1)
  {
  }
  return 0;
}

生成文件

MCU = atmega32
# Target file name (without extension).
TARGET = main
AVRDUDE_PROGRAMMER = avrisp
AVRDUDE_PORT = COM3
OPT = s
FORMAT = ihex
SRC = $(TARGET).c
#SRC += TimerOne.cpp
EXTRAINCDIRS = 
CLOCK = 14745600
CPU = F_CPU=$(CLOCK)


# Optional compiler flags.
#  -g:        generate debugging information (for GDB, or for COFF conversion)
#  -O*:       optimization level
#  -f...:     tuning, see gcc manual and avr-libc documentation
#  -Wall...:  warning level
#  -Wa,...:   tell GCC to pass this to the assembler.
#    -ahlms:  create assembler listing
CFLAGS = -g -O$(OPT) \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall \
$(patsubst %,-I%,$(EXTRAINCDIRS))

# -lm = math library
LDFLAGS = -lm
AVRDUDE = avrdude
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) -b 19200
AVRDUDE_FLAGS += -v
# ---------------------------------------------------------------------------

# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib

# Define programs and commands.
CC = avr-g++ -D$(CPU) -D$(MCU)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
REMOVE = rm -f
COPY = cp
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -AC --mcu=$(MCU) $(TARGET).elf

# Define all object files.
OBJ = $(patsubst src%,obj$(VERSION)%,$(patsubst %.c,%.o,$(SRC)))
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)

# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)

# Default target: make program!
all: main.hex

main.hex: main.elf
    $(OBJCOPY) -O $(FORMAT) -R .eeprom main.elf main.hex

main.elf:  main.o
    $(CC) $(ALL_CFLAGS) main.o --output main.elf $(LDFLAGS)

main.o: 
    @echo
    @echo $(MSG_COMPILING) $<
    $(CC) -c $(ALL_CFLAGS) main.c -o $@

# Program the device.  
program: $(TARGET).hex
    $(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(TARGET).hex

# Flash the device
flash:
    $(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:w:0xFF:m -U hfuse:w:0x89:m

# Target: clean project.
clean: begin clean_list finished end

clean_list :
    @echo
    @echo $(MSG_CLEANING)
    $(REMOVE) $(TARGET).hex
    $(REMOVE) $(TARGET).eep
    $(REMOVE) $(TARGET).obj
    $(REMOVE) $(TARGET).cof
    $(REMOVE) $(TARGET).elf
    $(REMOVE) $(TARGET).map
    $(REMOVE) $(TARGET).obj
    $(REMOVE) $(TARGET).a90
    $(REMOVE) $(TARGET).sym
    $(REMOVE) $(TARGET).lnk
    $(REMOVE) $(TARGET).lss
    $(REMOVE) $(TARGET).o

# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
    clean clean_list program

1 个答案:

答案 0 :(得分:1)

看来我只需要问这个问题,然后在经过几天的搜索后我终于找到答案了。通常情况下,答案就在数据表中。问题是保险丝位。默认情况下,JTAG接口已启用,这是PORTC的一部分。这就是PORTC无法正常工作的原因。我将HFUSE位从0x89更新为0xC9。这禁用了JTAG接口,PORTC就像普通的IO端口一样。