Hello , I'm using atmega328p in my PCB project, and I'm using light led , my problem is when I powered ON the atmega328p . it takes 3 seconds to light the led. what exactly the problem?
I want to be more quickly.
Maybe Remove the delay(3000);
you have in the setup?
Joke aside, could be your boot loader waiting . Need more info on your code and configuration
(do yourself a favour and please read How to get the best out of this forum).
This is my code
Which arduino and boot loader?
Get rid of the serial stuff at the start - just set the pin as output and, turn your led on in the setup
I'm using atmega328p , bootloader ArduinoISP
Any chance you ditch the boot loader on this 328 ?
There are many articles out there discussing this - here is a first random hit
That doesn't compile, you're missing a } after loop()
More serious now, when posting code, click the </> button (in the forum) and paste the code.
Let's see a full schematic.
"ArduinoISP" is a programmer, an external piece of hardware used to write to the flash of a microcontroller using some specialized interface (in this case via the three SPI pins plus reset).
A bootloader is software, a program loaded onto the flash prrior to any sketch, to enable programming through some mechanism more convenient than the native interface that the above-described programmer uses - in the arduino world, this more convenient interface is almost always serial. The bootloader is run immediately after reset or power on, before any sketch starts.
In the case of an ATmega328p in Arduino-land, the bootloader will wait a short period of time, listening to the serial pins for an attempt to upload a new sketch - if not, it will start the sketch. The serial adapter is rigged to reset the board whenever the serial port is opened (well, whenever the DTR line is brought low, which is done automatically by most serial consoles - the widely discussed "DTR autoreset" circuit), which is how your sketch restarts when you open the serial monitor.
With the best bootloader for the 328p in Arduino-land (the one that ships on the Uno), a bootloader called "Optiboot, the bootloader will wait for just half a second, and only after the part is reset using the reset pin (see comment), not on a cold power-on. However, the Arduino Nano ("Arduino Nano 3.0", or "Arduino Nano". not "Arduino Nano Some-other-word" - not long ago they released three other "Nano" boards, each with a different word after it - all three of which have different architectures, none of which is the same as the original Nano! Not their first time with confusingly similar names for boards...) and Arduino Pro Mini , both of which use the same processor as the Uno, have a more primitive bootloader, which uses a different (slower) baud rate and waits longer for an upload - I think either 2 or 4 seconds - and waits regardless of the reset method (see third comment).
I think that the most likely cause of your delay is that you're using the nano or pro mini bootloader. Hence, every time you turn it on, before running your sketch, it first waits for a few seconds to see if you're trying to upload a new one.
The resolution is simple:
If it is acceptable for the delay to be half a second after a reset pin reset (no delay at poweron), and you do want to upload normally, via serial, you can simply bootload it with a modern version of Optiboot. If it uses a 16 MHz crystal or resonator (like a 16 MHz 5v pro mini or nano), you need only tell the IDE that it's an Uno, connect your external ISP programmer, tools -> burn bootloader), if it's 8 MHz or some other speed, install MiniCore; that has Optiboot included for any operating frequency a sane and reasonable person would wan. Either way, after successfully burning bootloader, you must always have the same board (and frequency, if applicable) selected when you upload that you had when you burned the bootloader. Be careful here - if you "burn bootloader" with a board definition selected that does use a crystal, but you have no crystal connected because you want to use the internal clock, with is 8 MHz (approximately - that's why even most people running at 8 MHz use a crystal), you will not be able to reprogram it, including to set it to a different clock source, until you provide it with the crystal or a substitute clock (final note).
If it must start immediately, even when it resets from the reset pin, not just at power-on, you cannot program it through the bootloader - you must always use an ISP programmer. Install MiniCore as noted above, select Tools -> boards -> MiniCore -> ATmega328. Select the desired clock, and select "No" for the bootloader. Connect your ISP programmer and burn bootloader. You will have to connect the ISP programmer whenever you upload to it - using those same settings, the IDE is smart enough to know to use the ISP programmer for uploads.
Notes:
1 - The bootloader runs after any sort of reset, unless the board is not set to have any bootloader. Optiboot is very clever - it checks the reset cause flags (which are reset only by software action or upon power on reset); if the one corresponding to the WDT is set, it clears that one and jumps to the application. Otherwise, if the reset pin reset cause flag is not set, it will also jump to the application. If reset pin reset, but not watchdog reset flags are set, it will wait half a second for upload before (and here's the clever part) using the WDT reset to reset the chip, at which point the booloader will run, see that WDT reset flag is set, clear it, and jump to the application. This reset makes sure that your application gets to start from a freshy reset chip. I have seen code from the dark ages before that trick was known in Arduino circles which reinitializes peripherals before using them, with comments like "in case the bootloader left a mess"....
2- This older bootloader version also gets stuck in a bootloop if you reset it using the WDT.
3 - Per datasheet, the spi frequency used for uploads must be 6 times the system clock. If it's set to use a crystal, but no crystal is present, the system clock frequency is 0.
Thank yo , I resolved it .
That was from the bootloader
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.