2

enter image description hereI built my first custom circuit board with an Atmel ATMega328p-AU the tqfp-32 form factor. I connected xtal1 and xtal2 to an external 16mhz crystal to 22pf caps tied to ground. It seems to work great, I load the Arduino Bootloader using AVRDude and an arduino as an isp. As soon as I load a sketch on using the ftdi it blows out the bootloader and I can't upload a new sketch until reloading the bootloader. The sketch works as expected, my board has an on board relay and an onboard mosfet I've programmed various blink patterns on both the mosfet and relay.I just don't want to have to reload the bootloader everytime I want to make a change, my sketch is an evolving piece of work and it's frustratinf to take these steps. So far I've tried changing the lock bits to 0x0F 0xEF 0xFF and 0X2F. I've tried various fuse bits, I've changed the signature 0x1e 0x95 0x14 to 0x1e 0x95 0x0F. Nothing seems to change the results, the only thing I've managed to do is one upload caused the chip to run at 8mhz instead of 16mhz, oops. That was easily fixed though. Please if someone can help that would be great, unfortunately the fuse bit calculators I have found don't have the 16mhz crystal as an option even though it's clearly functional.

In Summary

Sketches overwrite my bootloader and I want my bootloader locked but I can't find a solution after nearly a full day of googling and experimenting

7
  • ... probably should also have pin 6 of the ATmega328p connected to Vcc as well, but probably doesn't explain your problem.
    – vicatcu
    Dec 2, 2016 at 23:56
  • 1
    ... you also want a fly-back diode across your solenoid header, and across your relay coil, probably, or those NPN transistors may not be long for this world, but again not related to this question
    – vicatcu
    Dec 3, 2016 at 0:00
  • sorry, bad schematic, pin 6 is connected to vcc
    – Cfoote7
    Dec 3, 2016 at 0:01
  • ...7805 regulator probably needs bulk capacitors 10uF on its input and output too, but again probably not related...
    – vicatcu
    Dec 3, 2016 at 0:02
  • the output has a 100nf in line with the 7805's output, maybe a little low, so I may correct that on my next revison, particularly if I have an issue with power, the input power has another pcb I created with the output being ran through a 100uf cap. clearly this board is just a small part of a much larger piece of hardware, but to keep it simple I'm just showing the schematics for this board. There's a total of 4 different circuit boards, a custom power supply, 400 pull actuator solenoid, 400 of these boards, 400 rfid antenna's and a single rfid decoder, all connected to a beaglebone via uart.
    – Cfoote7
    Dec 3, 2016 at 0:09

2 Answers 2

1

Almost certainly your fuses are wrong. The fuses tells it whether or not to run the bootloader. With an empty PROGMEM (ie. no sketch) the processor probably skips over all the 0xFF bytes until it hits the bootloader. Once you have a sketch there it will run the sketch.

On my Uno (which is an Atmega328P) running at 16 MHz from a crystal, my fuses are:

Low = FF High = DE Ext = FD Lock = EF 

I suggest you visit http://www.engbedded.com/fusecalc to work out fuse settings.

You want the BOOTRST fuse set (that is, the high fuse should be 0xDE or something with the low-order bit clear). On the AVR chips, having a bit clear (0) means the fuse is set.

I have a bootloader programmer sketch which not only puts the bootloader there, it sets the correct fuse bit.

I also have a chip detector sketch which will tell you the current fuse settings.

0

I suspect you aren't writing the fuses on the AVR correctly in some way (or at all?). Try using the "Tools > Burn Bootloader" functionality of the IDE itself (which will set the fuses as well as loading the flash). You have to make sure you pick your ISP programmer under tools as well for this to work (e.g. Arduino as ISP). See if that works any better for you.

As an aside, there are a variety of AVR online fuse calculators if you're not into reading the datasheet. For example, http://www.engbedded.com/fusecalc. I seem to remember some rumblings in recent history that full swing external crystal configurations wouldn't be supported in new silicon for the ATmega328p, but that's what I always used to pick, and I think it probably still works as a setting.

Honestly, though, the easiest thing to do is to run Arduino in verbose (check the boxes in Preferences) and borrow their avrdude commands that get displayed when you run Burn Bootloader.

Continuations...

If that (Burn Bootloader) doesn't work for you, we're going to need to see some schematics, and I'd be staring pretty hard at your reset sub-circuit and FTDI sub-circuit.

Arduino Uno bootloader wants you to talk to it at 115200 baud... see the boards file.

What do you mean "My IDE doesn't hae a 328p UNO"? Download the latest Arduino from https://www.arduino.cc/en/Main/Software and choose Genuino Uno.

enter image description here

9
  • Thanks vicatcu, I've ran the AVRDude in cli mode with various fusebits set and lockbits. None of the settings I try seems to work. I've also ran arduino ide in verbose mode and tried to burn the bootloader from there, I get the same thing. I used Arduin as ISP and I set the board as the pro because it uses the same microprocessor. Unfortunately as I mentioned in my post the online calculators I've found don't have the 16mhz crystal option. if you look at the engbedded.com/fusecalc website you'll find they don't have the 16mhz crystal listed as an option on the 328p.
    – Cfoote7
    Dec 2, 2016 at 23:48
  • @Cfoote7 they do have 16MHz, it's just listed as "8.0 - Mhz" meaning 8MHz and up. I would just pick the last one in the dropdown (maximum frequency, slowest startup), also you can probably safely choose the Uno as your board in the IDE, give that a try?
    – vicatcu
    Dec 2, 2016 at 23:50
  • 1
    @Cfoote7 You are just clicking upload when you want to load over USB right? Make sure you aren't choosing Upload using Programmer. Because that will blow away the bootloader... on purpose.
    – vicatcu
    Dec 2, 2016 at 23:54
  • I tried burning it as an Uno, it wouldn't even load a sketch once after I did that. I switched it back to the pro and I could burn a sketch again. Also I attached my schematics, I realize the ftdi is configured incorrectly but I fixed that by connecting the pins differently.
    – Cfoote7
    Dec 2, 2016 at 23:58
  • yes I'm just clicking upload and I'm using and rs-232 adapter set to 57600 baud to upload sketches. where as I'm using an arduino for loading the bootloader
    – Cfoote7
    Dec 2, 2016 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.