USB_Mega 调试1 --- 开发板测试

来源:互联网 发布:人工智能要那些专业 编辑:程序博客网 时间:2024/04/28 04:46

1。买的万用表二极管档输出能力过大,导致所有Mega芯片IO脚对END正向短路,VCC对IO脚正向短路。

2。Mega芯片出厂配置一般为内部时钟1MHz,采用USBasp下载时,要调整USBasp的下载速度(短接跳线),改变熔丝位之后再调回高速。

3。Mega熔丝配置为外部晶体震荡,但是因为没有起震而不能下载时,可从其他芯片X2脚引线到不能下载芯片X1脚。

4。FT232BM安装官网驱动即可识别并有相应的COM口。

5。max232 外面的电容,如果是max232xxA型号全部接0.1u,如果是max232xx型号全部接1uf。在我板子上实验max232cse外接0.1u也是正常的,呵呵。BTW,无极性有机性的均可。 最重要的一点:TTL和RS232电平接口要分清,两套接口的名字画封装的时候很类似,结果两套就接反了,刻断飞线之后还能用,万幸! 

6。max232的2脚本来接电容到VCC上,但是从原来的一个图利copy过来,2脚经过电容接地貌似也没不正常,哈哈。

7。今天调试,遇到一个坑爹的问题。Mega16在JTAG使能的时候PORTC相关的几个脚(PORTC2,3,4,5)不能当IO用。 对他们的置位将不能达到正常电平。

  使用软件可以禁用JTAG:MCUCSR = 0x80;    但是实验发现此时PORTC3 (TDO)脚仍然不正常,不能当IO脚用。只有当在熔丝位配置里面禁用JTAG之后,JTAGEN=1才正常。

Tips:Mega系列熔丝位1表示未编程,0表示编程。

8.配置开发环境:

  主机:Ubuntu10.10 i386 Desktop edition network availble

  软件: 编译软件avr-gcc; 下载软件:avrdude

  硬件:此开发板,USB转串口线,USB公口转公口线,USBasp下载线,5V电源适配器。

   主芯片:mega8(12Mhz)和Mega16(16Mhz)。

   

如图通过一个双刀双掷开关选择编程Mega8或者Mega16。

10.测试程序: hello,world  && Led

#define F_CPU 16000000#include <stdio.h>#include <avr/io.h>#include <avr/interrupt.h>#include <avr/wdt.h>#include <util/delay.h>#define BIT _BVvoid board_test(){  DDRC = 0xf0;  wdt_disable();  while(1)  {    _delay_ms(500);    PORTC |= 0xf0;    _delay_ms(500);    PORTC &= 0x0f;  }}void init_port(){  DDRC  = 0xf0;  PORTC = 0x00;  DDRD  = 0x02;  PORTD = 0x00;  DDRA  = 0x00;  DDRB  = 0x00;}void put_char(char c){  while ( !(UCSRA & (1<<UDRE)) ) ;  UDR = c;}void init_uart(){ UCSRB = 0x00; UCSRA = 0x00; UCSRC = BIT(URSEL) | 0x06; UBRRL = 0x67; //set baud rate lo UBRRH = 0x00; //set baud rate hi UCSRB = 0x18;  void init_device(){  init_port();  init_uart();}int main(){  init_device();  //board_test();  put_char('a');  put_char('a');  put_char('a');  while(1);  return 0;}

Makfile:

#       Makefile for myUsb_Mega#       Based on:##   Makefile for usbasp#   20061119   Thomas Fischl        original#   20061120   Hanns-Konrad Unger   help: and TARGET=atmega48 added#TARGET=atmega16HFUSE=0xc9LFUSE=0x2f# ISP=bsd      PORT=/dev/parport0# ISP=ponyser  PORT=/dev/ttyS1# ISP=stk500   PORT=/dev/ttyS1# ISP=usbasp   PORT=/dev/usb/ttyUSB0# ISP=stk500v2 PORT=/dev/ttyUSB0ISP=usbaspPORT=/dev/usb/ttyUSB0help:        @echo "Usage: make                same as make help"        @echo "       make help           same as make"        @echo "       make main.hex       create main.hex"        @echo "       make clean          remove redundant data"        @echo "       make disasm         disasm main"        @echo "       make flash          upload main.hex into flash"        @echo "       make fuses          program fuses"        @echo "       make avrdude        test avrdude"        @echo "Current values:"        @echo "       TARGET=${TARGET}"        @echo "       LFUSE=${LFUSE}"        @echo "       HFUSE=${HFUSE}"        @echo "       CLOCK=16MHz"        @echo "       ISP=${ISP}"        @echo "       PORT=${PORT}"COMPILE = avr-gcc -Wall -O2 -I. -mmcu=$(TARGET) # -DDEBUG_LEVEL=2OBJECTS = main.o # isp.o clock.o tpi.o.c.o:        $(COMPILE) -c $< -o $@#-Wa,-ahlms=$<.lst.S.o:        $(COMPILE) -x assembler-with-cpp -c $< -o $@# "-x assembler-with-cpp" should not be necessary since this is the default# file type for the .S (with capital S) extension. However, upper case# characters are not always preserved on Windows. To ensure WinAVR# compatibility define the file type manually..c.s:        $(COMPILE) -S $< -o $@clean:        rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o main.s# file targets:main.bin:       $(OBJECTS)        $(COMPILE) -o main.bin $(OBJECTS) -Wl,-Map,main.mapmain.hex:       main.bin        rm -f main.hex main.eep.hex        avr-objcopy -j .text -j .data -O ihex main.bin main.hex#       ./checksize main.bin# do the checksize script as our last action to allow successful compilation# on Windows with WinAVR where the Unix commands will fail.disasm: main.bin        avr-objdump -d main.bincpp:        $(COMPILE) -E main.cflash:        avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -U flash:w:main.hexfuses:        avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):mavrdude:        avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v# Fuse atmega16 high byte HFUSE:# 0xc9 = 1 1 0 0   1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)#        ^ ^ ^ ^   ^ ^ ^------ BOOTSZ0#        | | | |   | +-------- BOOTSZ1#        | | | |   + --------- EESAVE (don't preserve EEPROM over chip erase)#        | | | +-------------- CKOPT (full output swing)#        | | +---------------- SPIEN (allow serial programming)#        | +------------------ JTAGEN#        +-------------------- RSTDISBL (reset pin is enabled)# Fuse atmega16 low byte LFUSE:# 0x9f = 1 0 0 1   1 1 1 1#        ^ ^ \ /   \--+--/#        | |  |       +------- CKSEL 3..0 (external >8M crystal)#        | |  +--------------- SUT 1..0 (crystal osc, BOD enabled)#        | +------------------ BODEN (BrownOut Detector enabled)#        +-------------------- BODLEVEL (2.7V)## Fuse atmega48 high byte hfuse:# 0xdf = 1 1 0 1   1 1 1 1     factory setting#        ^ ^ ^ ^   ^ \-+-/#        | | | |   |   +------ BODLEVEL (Brown out disabled)#        | | | |   + --------- EESAVE (don't preserve EEPROM over chip erase)#        | | | +-------------- WDTON (WDT not always on)#        | | +---------------- SPIEN (allow serial programming)#        | +------------------ DWEN (debug wire is disabled)#        +-------------------- RSTDISBL (reset pin is enabled)# 0xdd = ext.reset, no DW, SPI, no watchdog, no save eeprom, BOD 2.7V# Fuse atmega48 low byte lfuse:# 0x62 = 0 1 1 0   0 0 1 0     factory setting#        ^ ^ \ /   \--+--/#        | |  |       +------- CKSEL 3..0 (internal 8Mhz Oszillator)#        | |  +--------------- SUT 1..0 (start-up time)#        | +------------------ CKOUT (no clock output)#        +-------------------- CKDIV8 (divide clock by 8)# 0xdc = divide/1,no clock output,fast raising power,low Pw Oszil. 3..8 Mhz# 0xe0 = divide/1,no clock output,fast raising power,external Oszil.# 0xff = divide/1,no clock output,slow raising power,low Pw Oszil 8..  MhzSERIAL = `echo /dev/tty.USA19QI*`UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto# The two lines above are for "uisp" and the AVR910 serial programmer connected# to a Keyspan USB to serial converter to a Mac running Mac OS X.# Choose your favorite programmer and interface.uisp:   all        $(UISP) --erase        $(UISP) --upload --verify if=main.hex

Windows:   

//ICC-AVR application builder : 2011-11-22 9:39:42// Target : M16// Crystal: 16.000Mhz#include <iom16v.h>#include <macros.h>#include <stdio.h> extern int _textmode; int putchar(char c)    {    if (_textmode && c == '\n')        putchar('\r');    /* Wait for empty transmit buffer */    while ( !(UCSRA & (1<<UDRE)) )        ;                         /* Putting data into buffer , sends the data */    UDR = c;      return c;    }void port_init(void){ PORTA = 0x00; DDRA  = 0x00; PORTB = 0x00; DDRB  = 0x00; PORTC = 0x00; //m103 output only DDRC  = 0x00; PORTD = 0x00; DDRD  = 0x02;}//UART0 initialize// desired baud rate: 9600// actual: baud rate:9615 (0.2%)void uart0_init(void){ UCSRB = 0x00; //disable while setting baud rate UCSRA = 0x00; UCSRC = BIT(URSEL) | 0x06; UBRRL = 0x67; //set baud rate lo UBRRH = 0x00; //set baud rate hi UCSRB = 0x18;}//call this routine to initialize all peripheralsvoid init_devices(void){ //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); uart0_init(); MCUCR = 0x00; GICR  = 0x00; TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized}void main(){  init_devices();    printf("Hello,world!\r\n");  while(1);}

//ICC-AVR application builder : 2011-11-22 9:46:32// Target : M8// Crystal: 12.000Mhz#include <iom8v.h>#include <macros.h>#include <stdio.h>extern int _textmode; int putchar(char c)    {    if (_textmode && c == '\n')        putchar('\r');    /* Wait for empty transmit buffer */    while ( !(UCSRA & (1<<UDRE)) )        ;                         /* Putting data into buffer , sends the data */    UDR = c;      return c;    }void port_init(void){ PORTB = 0x00; DDRB  = 0x00; PORTC = 0x00; //m103 output only DDRC  = 0x00; PORTD = 0x00; DDRD  = 0x02;}//UART0 initialize// desired baud rate: 9600// actual: baud rate:9615 (0.2%)void uart0_init(void){ UCSRB = 0x00; //disable while setting baud rate UCSRA = 0x00; UCSRC = BIT(URSEL) | 0x06; UBRRL = 0x4D; //set baud rate lo UBRRH = 0x00; //set baud rate hi UCSRB = 0x18;}//call this routine to initialize all peripheralsvoid init_devices(void){ //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); uart0_init(); MCUCR = 0x00; GICR  = 0x00; TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized}void main(){  init_devices();    printf("Hello,world!\r\n");  while(1);}

总结:这次的板子除了串口芯片接错线外,电源的设计也不是很方便。原来想着电源输入之后经过7805稳压共给下面的芯片。但是手边都是220V转5V的电源,没找到7v之上的适配器。最后还是把7805短接了才能用5V的适配器。以后样板可以考虑加个开关或者调线。

板子整体来说还是蛮不错的~~ 嘻嘻......


原创粉丝点击