OpenSprinkler › Forums › OpenSprinkler Unified Firmware › Programming a new Atmega328-PU
- This topic has 9 replies, 1 voice, and was last updated 3 years, 8 months ago by
nsethi.
-
AuthorPosts
-
June 2, 2013 at 9:28 am #22453
BambamParticipantI put together an OS 1.42u these days and it was working straight away. That made me very happy and a bit proud since I’m not such an expert on electronics. But I am much more impressed by the work developing the OP, keeping the homepage updated etc. Congratulations – what an outstanding work!
I would like to do a few alterations on the source code. However, at first I have to learn and understand how to program the MCU and so on. For that reason at first I wanted to program a brand new Atmega328-PU with the precompiled firmware avoiding to mess up the original Atmega from rayshobby and ending up in serious trouble. I’ve got everything working out so far, however the ISP doesn’t reach the MCU. Avrdude is giving me following messages
c:>avrdude -c usbtiny -p m328p -F -U flash:w:firmware1.8.3.hex
avrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
avrdude: Expected signature for ATMEGA328P is 1E 95 14
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performedTo disable this feature, specify the -D option.
avrdude done. Thank you.
A device signature of 0x0 indicates that the ISP can not communicate with the MCU. I guess that is due to the setting of the fuse bits of the unused mcu. If that is true, I should add a crystal (8 or 16 MHz) to the pins of position “X1” on the board and follow the instructions given here by Ray. Am I right?
If that would solve my problem, my next question would be, could I leave the crystal soldered to the board? OP uses its internal clock by setting the appropriate fuse bits. The external crystal would remain unused and wouldn’t matter.
June 7, 2013 at 2:32 am #23800
RayKeymasterTo program a new mcu, you need to do the following:
1) program the fuse bits:
avrdude -c usbtiny -p m328p -B 250 -F -U lfuse:w:0xe2:m -U hfuse:w:0xd1:m -U efuse:w:0x06:m
(this sets various configurations, including setting the mcu to run with internal 8MHz clock. the -B 250 part is important because OpenSprinkler’s built-in usbtiny programmer is set to run at the highest speed, and a stock atmeg328 runs only at 1MHz so it cannot handle that speed. therefore you need to first use a slow programming speed to set the clock to run at 8MHz).2) flash the firmware:
avrdude -c usbtiny -p m328p -F -U flash:w:firmware1.8.3.hexJune 7, 2013 at 4:03 pm #23801
BambamParticipantExcellent, it now works! Thank you ever so much, Ray.
1) I set the fuse bits with the following results:
c:>avrdude -c usbtiny -p m328p -B 250 -F -U lfuse:w:0xe2:m -U hfuse:w:0xd1:m -U efuse:w:0x06:m
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.09s
avrdude: Device signature = 0x1e9514
avrdude: reading input file “0xe2”
avrdude: writing lfuse (1 bytes):Writing | ################################################## | 100% 0.08s
avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xe2:
avrdude: load data lfuse data from input file 0xe2:
avrdude: input file 0xe2 contains 1 bytes
avrdude: reading on-chip lfuse data:Reading | ################################################## | 100% 0.03s
avrdude: verifying …
avrdude: 1 bytes of lfuse verified
avrdude: reading input file “0xd1”
avrdude: writing hfuse (1 bytes):Writing | ################################################## | 100% 0.09s
avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xd1:
avrdude: load data hfuse data from input file 0xd1:
avrdude: input file 0xd1 contains 1 bytes
avrdude: reading on-chip hfuse data:Reading | ################################################## | 100% 0.03s
avrdude: verifying …
avrdude: 1 bytes of hfuse verified
avrdude: reading input file “0x06”
avrdude: writing efuse (1 bytes):Writing | ################################################## | 100% 0.08s
avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0x06:
avrdude: load data efuse data from input file 0x06:
avrdude: input file 0x06 contains 1 bytes
avrdude: reading on-chip efuse data:Reading | ################################################## | 100% 0.03s
avrdude: verifying …
avrdude: 1 bytes of efuse verifiedavrdude: safemode: Fuses OK
avrdude done. Thank you.
2. flashing the firmware
c:>avrdude -c usbtiny -p m328p -F -U flash:w:firmware1.8.3.hexavrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9514
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performedTo disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file “firmware1.8.3.hex”
avrdude: input file firmware1.8.3.hex auto detected as Intel Hex
avrdude: writing flash (32384 bytes):Writing | ################################################## | 100% 12.87s
avrdude: 32384 bytes of flash written
avrdude: verifying flash memory against firmware1.8.3.hex:
avrdude: load data flash data from input file firmware1.8.3.hex:
avrdude: input file firmware1.8.3.hex auto detected as Intel Hex
avrdude: input file firmware1.8.3.hex contains 32384 bytes
avrdude: reading on-chip flash data:Reading | ################################################## | 100% 9.92s
avrdude: verifying …
avrdude: 32384 bytes of flash verifiedavrdude: safemode: Fuses OK
avrdude done. Thank you.
September 20, 2013 at 3:26 am #23802
dbrack1ParticipantRay,
I am doing this same thing except with the 644A. Are the fuse bits the same?
Thanks
September 21, 2013 at 11:35 am #23803
RayKeymasterTo program a blank mega644 chip, use the following:
avrdude -c usbtiny -p m644 -B 250 -U lfuse:w:0xe2:m -U hfuse:w:0xd1:m -U efuse:w:0xfe:m
(in case avrdude complains the signature does not match, add a -F option to overwrite the signature checking)Then you can flash a firmware with:
avrdude -c usbtiny -p m644 -U flash:w:firmware2.0.0.hexSeptember 22, 2013 at 4:02 am #23804
dbrack1ParticipantSame error, any other ideas?
C:WinAVRbin>avrdude -c usbtiny -F -p m644 -B 250 -U lfuse:w:0xe2:m -U hfuse:w:
0xd1:m -U efuse:w:0xfe:mavrdude: initialization failed, rc=-1
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
avrdude: Expected signature for ATMEGA644 is 1E 96 09avrdude done. Thank you.
September 22, 2013 at 8:44 am #23805
RayKeymasterThat can come out of a variety of reasons. For example, the programming is not connected properly to the mcu, the mcu is not up running (due to clock source problem etc). You can Google the error message ‘initialization failed, rc=-1’ to see potential causes.
September 23, 2013 at 12:19 am #23806
dbrack1ParticipantI figured it out, I just needed to close the SJ1 jumper in order to program.
Thanks
May 19, 2014 at 7:41 pm #23807
rickyoo11MemberI am having same situation here and i have Atmega32.
What would be the command for the Atmega32?
ThanksMay 20, 2014 at 4:42 pm #23808
RayKeymasterATmega32 is very different from ATmega328 — they have different number of pins and the internal modules are also different. Are you sure you have ATmega32?
June 1, 2021 at 1:56 pm #70290
nsethiParticipantIt is great to have these old messages still archived. I needed to replace my atmega328 microcontroller from my self soldered 1.42u board and ran into the problem in this thread.
Perhaps also update the wiki article here: https://rayshobby.net/wordpress/opensprinkler/svc-use/opensprinkler-firmware-compilation-instructions-archived/
Thanks.
-
AuthorPosts
- You must be logged in to reply to this topic.
OpenSprinkler › Forums › OpenSprinkler Unified Firmware › Programming a new Atmega328-PU