MCUdude / MiniCore

Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB
Other
995 stars 245 forks source link

Atmega328PB doesn't program properly #195

Closed v-sadovsky closed 3 years ago

v-sadovsky commented 3 years ago

Hi

Thanks for the provided minicore!

I have a custom board based on the atmega328PB chip. ArduinoIDE version is 1.8.15, Arduino AVR Boards version 1.8.3 is installed, MiniCore by MCUdude version 2.1.2 is installed, my OS is Windows 10.

The following steps were done:

  1. Tools->Board->MiniCore->Atmega328 chosen
  2. Clock Internal 8MHz, BOD 2.7V, EEPROM retained, LTO disabled, Variant 328PB, No bootloader, Programmer AVRISP MKII
  3. Burn bootloader After these steps, I sow in the console output that the programming was done successfully.

Next, I tried to test my board with a simple "blinking" sketch:

#define LED1 PD2

void setup() {
   pinMode(LED1, OUTPUT);
}

void loop() {
   digitalWrite(LED1, 1);
   delay(500);
   digitalWrite(LED1, 0);
   delay(500);
}

After uploading the code I connect to the defined pin a LED probe and all works fine - the LED is blinking. But when I try to use, for instance, PCn or PEn pin for the same purpose it works strange - the defined pin does not work, but PDn is working instead.

I tried to use Microchip studio for programming this board and all works fine. Am I doing something wrong with the ArduinoIDE?

Regards

MCUdude commented 3 years ago

Hi!

If you want to use "Arduino functions" such as digitalWrite, you can't use PD0, PE0, and so on. These only represent what bit on a port to manipulate.

This means that this is defined in the avr-libc source files:

#define PD0 0
//...
#define PD7 7

#define PE0 0
//...
#define PE7 7

What you should do instead is to use PIN macros. This will always work with pinMode/digitalRead/digitalWriteWrite

digitalWrite(PIN_PD0, HIGH);
digitalWrite(PIN_PE0, HIGH);
v-sadovsky commented 3 years ago

Thanks! With these macros all works fine!