Hello everyone, I have a problem with bootloader to Atmega328 (disassembled from arduino uno).
How I can run bootloader with this microcontroller?
I have external crystal 16MHz and I must use UART with software reset.
I programmed microcontroller by bootloader_M328P.hex file from firmwares folder but microcontroler does not respond.
I'm sorry for my poor English.
Best regards Tomek.
(Since it is an external clock, the value of OSCCAL is invalid.)
③Initial programming of the user program is written without using software reset.
④The reception process of 'ABC' is described not in the bootloader but in the user program.
Serial reception is interrupt operation.
Execute the reset command when 'A', 'B', 'C' are received consecutively.
(The bootloader is always started when a reset is applied.)
⑤Process flow
<Target> <Host>
Power ON
Bootloader activation.
Bootloader timeout.
Move to user program.
(Waiting for command input) Start-up Continuously send 'A', 'B', 'C'.
Command reception
Reset
Bootloader activation. Send 0xC1
Received 0xC1 User program transmission.
Reception complete.
Bootloader timeout.
Move to new user program.
.
.
.
From Dan
Last edit: Dan 2016-12-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Dan, thank you for your answer.
Bootloader is already running but my program is not executed. How do I set fuse bits to everything correctly?
My program is "Arduino Blink"
I can send my hex using the bootloader if I manually reset the processor but led not blinking.
My bootloader modification:
;changetheselinesaccordinglytoyourapplication.include"m328Pdef.inc".equFamilyAVR=0x32;AVRFamily("1":ATtiny,"2":ATmega).equIdTypeAVR=0x25;mustexistsin"piccodes.ini"#define max_flash 0x4000 ; in WORDS, not bytes!!! (= 'max flash memory' from "piccodes.ini" divided by 2).equxtal=16000000;youmayalsowanttochange:_HS_OSC_XT_OSC.equbaud=19200;standardTinyBldbaudrates:115200or19200;.equCalib=0x93;8MHzCalibrationvalue;Theabove8linescanbechangedandbuidabootloaderforthedesiredfrequency;+---------+---------+--------+------------+------------+-----------+--------+------+;|AVRFamily|IdTypeAVR|Device|Erase_Page|Write_Page|max_flash|EEPROM|PDIP|;+---------+---------+--------+------------+------------+-----------+--------+------+;|0x32|0x25|M328P|64words|64words|0x4000|1024|28|;+---------+---------+--------+------------+------------+-----------+--------+------+;********************************************************************;TinyBootloaderATMEGA328PSize=132words;;ThisprogramisonlyavailableinTinyPICBootloader+.;(2013.07.22Revision1);;TinyPICBootloader+;https://sourceforge.net/projects/tinypicbootload/;;!!!!!SetFuseBitCKDIV8=1and8MHzCalibrationvalue!!!!!;;Pleaseaddthefollowinglinetopiccodes.ini;;$25,2,ATMEGA328P,$8000,1024,default,default,;;********************************************************************#define first_address max_flash-132 ; 132 word in size;reg#define crc r20#define cnt1 r21#define flag r22#define count r23#define temp r24#define rxd r25;I/Oreg#define UBRRL UBRR0L#define UCSRB UCSR0B#define UDR UDR0#define UCSRA UCSR0A;bit#define RXEN RXEN0#define TXEN TXEN0#define UDRE UDRE0#define RXC RXC0;macro.macroOUTILDIxh,high(@0)LDIxl,low(@0)STx,@1.endm.macroINILDIxh,high(@1)LDIxl,low(@1)LD@0,x.endm.macroSBISILDIxh,high(@0)LDIxl,low(@0)LDtemp,xSBRStemp,@1.endm.cseg;0000000000000000000000000RESET00000000000000000000000000.org0x0000;;Resetvector;RJMPIntrareBootloader.dw0xcf7f;RJMPPC-0x80;&&&&&&&&&&&&&&&&&&&&&&&START&&&&&&&&&&&&&&&&&;----------------------Bootloader----------------------;;PC_flash:C1hAddrHAddrLnr...(DataLoDataHi)...crc;PIC_response:idKK.orgfirst_address;nop;nop;nop;nop.orgfirst_address+4IntrareBootloader:;LDIrxd,Calib;set8MHzCalibrationvalue;OUTIOSCCAL,rxdLDIrxd,(xtal/(16*baud)-1)OUTIUBRRL,rxdLDIrxd,((1<<RXEN)|(1<<TXEN));RXon,TXonOUTIUCSRB,rxdRCALLReceive;waitforcomputerSUBIrxd,0xC1;ExpectC1BREQPC+2;skipifC1RJMPway_to_exit;connectionerrerortimeoutLDIrxd,IdTypeAVR;sendIdTypeRCALLrs1txMainLoop:LDIrxd,FamilyAVR;sendATmegaFamilyIDmainl:RCALLrs1txCLRcrc;clearChecksumRCALLReceive;getADR_HMOVr31,rxd;setr31MOVflag,rxd;setflagOUTEEARH,rxd;setEEARHRCALLReceive;getADR_LMOVr30,rxd;setr30OUTEEARL,rxd;setEEARLLSLr30;setPCPAGE:PCWORDROLr31SBIWr30,2;PCPAGE:PCWORD=PCPAGE:PCWORD-2RCALLReceive;getcountMOVcount,rxd;setcountrcvoct:RCALLReceive;getData(L)MOVr0,rxd;setData(L)OUTEEDR,rxd;setEEDRRCALLReceive;getData(H)MOVr1,rxd;setData(H)ADIWr30,2;PCPAGE:PCWORD=PCPAGE:PCWORD+2LDIrxd,(1<<SELFPRGEN);writebufferRCALLctrl_flashSUBIcount,2;count=count-2BRNErcvoct;loopRCALLReceive;getChecksumBRNEziieroare;Checksumerror?SBRCflag,6;isflash?RJMPeepromflash:LDIrxd,((1<<PGERS)+(1<<SELFPRGEN));eraseFlashPageRCALLctrl_flashLDIrxd,((1<<PGWRT)+(1<<SELFPRGEN));writeFlashPageRCALLctrl_flashRJMPMainLoop;loopeeprom:RCALLw_eeprom;writeEEPROMRJMPMainLoop;loopziieroare:LDIrxd,'N';send"N"RJMPmainl;retry;********************************************************************;;WriteEEPROM;;SetEEARL/EEDRandcall;;********************************************************************w_eeprom:SBICEECR,EEPERJMPw_eepromSBIEECR,EEMPESBIEECR,EEPERET;********************************************************************;;WriteandEraceflash/buffer;;SetR30:R31/R0:R1/rxdandcall;;********************************************************************ctrl_flash:INtemp,SPMCSRSBRCtemp,SELFPRGENRJMPctrl_flashOUTSPMCSR,rxdSPMRET;********************************************************************;;RS-232CSend1byte;;setrxdandcall;;********************************************************************rs1tx:SBISIUCSRA,UDRE;checkbufferemptyRJMPrs1txOUTIUDR,rxd;Send1byteRET;********************************************************************;;RS-232CRecive1byte;;returninrxd;;********************************************************************rs1rx:SBISIUCSRA,RXC;checkRecivedoneRJMPrs1rx;r1rx11:INIrxd,UDR;Recive1byteRET;********************************************************************;;RS-232CRecieve1bytewithTimeoutandCheckSum;;********************************************************************Receive:LDIcnt1,xtal/500000+1;for20MHz=>11=>1secondrpt2:CLRr28CLRr29rptc:;checkRecivedoneSBISIUCSRA,RXCRJMPPC+4RCALLr1rx11;get1byteADDcrc,rxd;computechecksumRETSBIWr28,1BRNErptcDECcnt1BRNErpt2way_to_exit:;CLRrxd;DisableRX,TX;OUTUCSRB,rxdRJMPfirst_address;timeout:exitinallothercases;********************************************************************;Afterreset;Donotexpectthememorytobezero,;Donotexpectregisterstobeinitialisedlikeincatalog.
My fuse bits on arduino uno board:
LOW: FF, HIGH: DE, EXT: FF, LOCK:3F
Hello everyone, I have a problem with bootloader to Atmega328 (disassembled from arduino uno).
How I can run bootloader with this microcontroller?
I have external crystal 16MHz and I must use UART with software reset.
I programmed microcontroller by bootloader_M328P.hex file from firmwares folder but microcontroler does not respond.
I'm sorry for my poor English.
Best regards Tomek.
Last edit: Tomek 2016-12-04
Hi,Tomek.
I think it is possible as follows.
①Change fuse bit to external clock.
②Changing the source and recompiling.
Change the value of xtal
.equ xtal = 16000000
(Since it is an external clock, the value of OSCCAL is invalid.)
③Initial programming of the user program is written without using software reset.
④The reception process of 'ABC' is described not in the bootloader but in the user program.
Serial reception is interrupt operation.
Execute the reset command when 'A', 'B', 'C' are received consecutively.
(The bootloader is always started when a reset is applied.)
⑤Process flow
<Target> <Host>
Power ON
Bootloader activation.
Bootloader timeout.
Move to user program.
(Waiting for command input)
Start-up
Continuously send 'A', 'B', 'C'.
Command reception
Reset
Bootloader activation.
Send 0xC1
Received 0xC1
User program transmission.
Reception complete.
Bootloader timeout.
Move to new user program.
.
.
.
From Dan
Last edit: Dan 2016-12-05
Hi Dan, thank you for your answer.
Bootloader is already running but my program is not executed. How do I set fuse bits to everything correctly?
My program is "Arduino Blink"
I can send my hex using the bootloader if I manually reset the processor but led not blinking.
My bootloader modification:
My fuse bits on arduino uno board:
LOW: FF, HIGH: DE, EXT: FF, LOCK:3F
Last edit: Tomek 2017-01-20
Hi,Tomek.
ATMEGA328P + Ex crystal 16MHz
-fL11010110 -fH11011001 -fx00000101 --> D6 D9 FD
From Dan
I give up, does not work.