D0 and D1 set to HIGH when booting the Arduino

Hi,

I have a project where I use a standalone AtMega328p-au on a PCB that I have designed. In my project I need to use the D0 and D1 (normaly used for TX/RX) as digital outouts. This part is OK, the only thing I have connected to the microcotroller pins for D0 and D1 is the LEDs that my project needs.

The problem is:

When I turn on the power to the circuit to boot the microcontroller, the microcontroller automaticly puts D0/RX to HIGH (powering on my LED on thet pin), and puts a 2.6v HIGH on the D1/TX pin. After the ~1.7 seconds the microcontroller needs to boot, the pins go LOW and all is fine.

Is it possible to stop the microcontroller from puting power on D1 and D0 (RX and TX) dooring the boot time?

That's the bootloader activating the serial port to see if you're trying to upload a new sketch after reset.

If you must prevent it from doing anything with those pins, you could use an ISP programmer instead of the bootloader yo program it.

But, consider if you could just shuffle what you use which pin for so that this behavior isnt ab issue

On a longer term note, if you swap to the 328pb (using MiniCore board package), you get a couple of extra pins (as well as better peripherals) for the same price.

DrAzzy: That's the bootloader activating the serial port to see if you're trying to upload a new sketch after reset.

If you must prevent it from doing anything with those pins, you could use an ISP programmer instead of the bootloader yo program it.

But, consider if you could just shuffle what you use which pin for so that this behavior isnt ab issue

On a longer term note, if you swap to the 328pb (using MiniCore board package), you get a couple of extra pins (as well as better peripherals) for the same price.

Thanks,

The PCBs are finished and I need to use the D0 and D1 to power two LEDs (this part is OK).

The thing I want to prevent is the Atmega328 to send power out on pin D0 and D1 (RX and TX) while the microcontroller is powerering on (takes about ~1.7seconds). That is because when I put power to the circuit, the two LEDs on D0 and D1 light up for a very short time (1.7 seconds), and I dont want that. After the 1.7 seconds, the LEDs turns off and everything is OK

HansiFansi: The thing I want to prevent is ...

I believe DrAzzy understood your question the first time and gave you the answer. If you did not understand the answer, please ask about it, don't just repeat the original question.

The problem you have is why using D0 & D1 is not recommended for beginners. Creating your own PCB for a circuit that you have not prototyped first (e.g. on breadboard) is also not recommended, as it can lead to difficult problems which could have been more easily solved at the prototype stage.

If you are using a bare atmega328, you may be able to use it without a crystal (8MHz internal clock). This would free up 2 more digital pins which are normally used to connect the crystal. You could use those instead of D0/D1. As mentioned, the MiniCore would allow these extra pins to be used.

PaulRB: I believe DrAzzy understood your question the first time and gave you the answer. If you did not understand the answer, please ask about it, don't just repeat the original question.

The problem you have is why using D0 & D1 is not recommended for beginners. Creating your own PCB for a circuit that you have not prototyped first (e.g. on breadboard) is also not recommended, as it can lead to difficult problems which could have been more easily solved at the prototype stage.

If you are using a bare atmega328, you may be able to use it without a crystal (8MHz internal clock). This would free up 2 more digital pins which are normally used to connect the crystal. You could use those instead of D0/D1. As mentioned, the MiniCore would allow these extra pins to be used.

DrAzzy: That's the bootloader activating the serial port to see if you're trying to upload a new sketch after reset.

If you must prevent it from doing anything with those pins, you could use an ISP programmer instead of the bootloader yo program it.

But, consider if you could just shuffle what you use which pin for so that this behavior isnt ab issue

On a longer term note, if you swap to the 328pb (using MiniCore board package), you get a couple of extra pins (as well as better peripherals) for the same price.

So I can change how the D0/D1 RX/TX pins behaves when booting the microcontroller? If so, is it no longer possible to program the chip? All I need in my project is the microcontroller to be programed once

There are two methods of programming the atmega chip with Arduino.

  1. Serial. Must use D0, D1 & RST. Difficult to use D0 & D1 pins for other purposes. You must have the Arduino bootloader already “burned” onto the chip.

  2. ISP. Must use MISO, MOSI, SCK & RST and a special programmer device such as USBAsp. No bootloader required. D0 & D1 can easilly be used for other purposes. MOSI, MISO & SCK can still be used for SPI comms with other chips.

HansiFansi: So I can change how the D0/D1 RX/TX pins behaves when booting the microcontroller? If so, is it no longer possible to program the chip? All I need in my project is the microcontroller to be programed once

Use an ISP programmer.

PaulRB: There are two methods of programming the atmega chip with Arduino.

  1. Serial. Must use D0, D1 & RST. Difficult to use D0 & D1 pins for other purposes. You must have the Arduino bootloader already "burned" onto the chip.

  2. ISP. Must use MISO, MOSI, SCK & RST and a special programmer device such as USBAsp. No bootloader required. D0 & D1 can easilly be used for other purposes. MOSI, MISO & SCK can still be used for SPI comms with other chips.

srnet: Use an ISP programmer.

Thanks! I can add that for my project I have an QFP32 adapter that I use to burn a 8MHz bootloader, and to program the code. After that I take the standalone Atmega328 and solder it to the PCB. Therfore the D0 and D1 is not connected to anything when I burn the bootloader or program the chip.

So the programming part is ok, but can I change the bootlader so that the D0 and D1 pins are just like D2-D13?

HansiFansi: So the programming part is ok, but can I change the bootlader so that the D0 and D1 pins are just like D2-D13?

The bootloader needs to use the D0 and D1 pins on an ATMega328P in order to work.

The ATMega328PB can be set to use its second hardware UART for the bootloader, so D0 and D1 would not be used, but then they wont be used if the sketch is loaded via an ISP programmer.

Did you breadboard the circuit before designing the PCB ?

Let’s try explaining this one more time…

The bootloader is a small program that is uploaded to the atmega using an ISP programmer. It allows subsequent code to be uploaded using serial (D0+D1) so that the ISP programmer is not needed again.

You only need to upload your code once. You have an ISP programmer (or it sounds like you have). So you don’t need to do further programming. Therefore you don’t need the bootloader. You can upload your code using your ISP programmer and use D0 + D1 as normal pins because the bootloader won’t be using them because there will be no bootloader present.

just upload the sketch using the isp programmer, and it will erase the bootloader.

The "right" way is to use minicore, which has full support for use without a bootloader - note that, confusingly, you still need to "burn bootloader" to set the fuses appropriately after selecting the the 328p and no bootloader - this gets you the extra 512b for your sketch that would be taken up by the bootloader.

Without this, the IDE will enforce the smaller limit, thinking there's a bootloader taking up that space, and if the fuses were set to what you'd need to use a bootloader, that space isn't usable anyway, because the chip jumps there on reset (fuses tell it there's a bootloader there), it runs through the empty flash (0xFFFF, ie, blank flash, is a no-op - if there was data there, this would choke), and wraps around to the reset vector and jumps to the start of the sketch.