OpenSprinkler Forums OpenSprinkler Unified Firmware Programming a new Atmega328-PU

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #22453

    Bambam
    Participant

    I 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 performed

    To 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.

    #23800

    Ray
    Keymaster

    To 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.hex

    #23801

    Bambam
    Participant

    Excellent, 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 verified

    avrdude: safemode: Fuses OK

    avrdude done. Thank you.

    2. flashing the firmware


    c:>avrdude -c usbtiny -p m328p -F -U flash:w:firmware1.8.3.hex

    avrdude: 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 performed

    To 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 verified

    avrdude: safemode: Fuses OK

    avrdude done. Thank you.

    #23802

    sloov187
    Participant

    Ray,

    I am doing this same thing except with the 644A. Are the fuse bits the same?

    Thanks

    #23803

    Ray
    Keymaster

    To 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.hex

    #23804

    sloov187
    Participant

    Same 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:m

    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 ATMEGA644 is 1E 96 09

    avrdude done. Thank you.

    #23805

    Ray
    Keymaster

    That 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.

    #23806

    sloov187
    Participant

    I figured it out, I just needed to close the SJ1 jumper in order to program.

    Thanks

    #23807

    rickyoo11
    Member

    I am having same situation here and i have Atmega32.
    What would be the command for the Atmega32?
    Thanks

    #23808

    Ray
    Keymaster

    ATmega32 is very different from ATmega328 — they have different number of pins and the internal modules are also different. Are you sure you have ATmega32?

    #70290

    nsethi
    Participant

    It 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.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums OpenSprinkler Unified Firmware Programming a new Atmega328-PU