Problems with board_build.mcu = atmega328pb

I am trying to load an old project on an Arduino Nano board. This time on Nano board is installed an ATmega328Pb so I added this line to the platformioini “ board_build.mcu = atmega328pb “ as I have done in the past. The result is the following:

Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial2.cpp.o
In file included from lib\NRF24L01\RF24_config.h:110:0,
                 from lib\NRF24L01\RF24.cpp:10:
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h: In static member function 'static void SPIClass::beginTransaction(SPISettings)':
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:203:5: error: 'SPCR' was not declared in this scope
     SPCR = settings.spcr;
     ^~~~
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:203:5: note: suggested alternative: 'SPCR0'
     SPCR = settings.spcr;
     ^~~~
     SPCR0
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:204:5: error: 'SPSR' was not declared in this scope
     SPSR = settings.spsr;
     ^~~~
In file included from lib\NRF24L01/RF24_config.h:110:0,
                 from lib\NRF24L01/RF24.h:18,
                 from src\main.cpp:2:
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h: In static member function 'static void SPIClass::beginTransaction(SPISettings)':
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:203:5: error: 'SPCR' was not declared in this scope
     SPCR = settings.spcr;
     ^~~~
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:204:5: note: suggested alternative: 'SPSR0'
     SPSR = settings.spsr;
     ^~~~
     SPSR0
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h: In static member function 'static uint8_t SPIClass::transfer(uint8_t)':
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:209:5: error: 'SPDR' was not declared in this scope
     SPDR = data;
     ^~~~
In file included from C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src\SPI.cpp:14:0:
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src\SPI.h: In static member function 'static void SPIClass::beginTransaction(SPISettings)':
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src\SPI.h:203:5: error: 'SPCR' was not declared in this scope
     SPCR = settings.spcr;
     ^~~~
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:209:5: note: suggested alternative: 'SPDR0'
     SPDR = data;


I have cut the most of the message in the middle because the error is the same.



C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src\SPI.h:298:5: error: 'SPCR' was not declared in this scope
     SPCR = (SPCR & ~SPI_MODE_MASK) | dataMode;
XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK);
     ^~~~
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:304:5: note: suggested alternative: 'SPSR0'
     SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((clockDiv >> 2) & SPI_2XCLOCK_MASK);
     ^~~~
     SPSR0
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h: In static member function 'static void SPIClass::attachInterrupt()':
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:309:42: error: 'SPCR' was not declared in this scope
   inline static void attachInterrupt() { SPCR |= _BV(SPIE); }
                                          ^~~~
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:309:42: note: suggested alternative: 'SPCR0'
   inline static void attachInterrupt() { SPCR |= _BV(SPIE); }
                                          ^~~~
                                          SPCR0
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h: In static member function 'static void SPIClass::detachInterrupt()':
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:310:42: error: 'SPCR' was not declared in this scope
   inline static void detachInterrupt() { SPCR &= ~_BV(SPIE); }
                                          ^~~~
C:\Users\gsrad\.platformio\packages\framework-arduino-avr\libraries\SPI\src/SPI.h:310:42: note: suggested alternative: 'SPCR0'
   inline static void detachInterrupt() { SPCR &= ~_BV(SPIE); }
                                          ^~~~
                                          SPCR0
*** [.pio\build\nanoatmega328\src\main.cpp.o] Error 1
*** [.pio\build\nanoatmega328\lib6ef\NRF24L01\RF24.cpp.o] Error 1
========================================================================== [FAILED] Took 1.12 seconds ======================================================================      



Just commenting out the line “board_build.mcu = atmega328pb “ the result is:

#Linking .pio\build\nanoatmega328\firmware.elf
Checking size .pio\build\nanoatmega328\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  10.9% (used 223 bytes from 2048 bytes)
Flash: [=         ]  12.9% (used 3952 bytes from 30720 bytes)
Building .pio\build\nanoatmega328\firmware.hex
========================================================================== [SUCCESS] Took 2.54 seconds =======================================================================

Please use preformatted text for logs and file content by simply enclosing the text in three backticks:

```
Your code or file content here
```

This increases readability enormously.

Please show the content of your platformio.ini.

; PlatformIO Project Configuration File

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
;board_build.mcu = atmega328pb
framework = arduino
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb

If could be of some interest i can sen to you also the complete folder of project

sorry i have just discover how
1 Like

A small example code to reproduce the issue would be helpful.

This compiles without problems:

main.cpp:

#include <Arduino.h>

void setup() {
	Serial.begin(115200);
	Serial.println("Hello World");
}

void loop() {}

platformio.ini:

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
board_create.mcu = atmega328pb
framework = arduino
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb
t#include <Arduino.h>
#include "RF24.h"

#define LUCI      4
#define BELL      5
#define FARI      6
#define GANCIO    7
#define CE_PIN    8
#define CSN_PIN   9
#define H_POT     A6
#define V_POT     A7

byte aux =  0;
int h_pot = 0;
int v_pot = 0;

struct dataStruct {
  char direzione;
  byte speed;
  byte sterzo;
  byte Tool;
} dataTosend;

RF24 radio(CE_PIN, CSN_PIN);             // Creo radio e definisco i pin
const uint64_t pipeOut = 0xE8E8F0F0E1LL; //  indirizzo dello slave

void setup() {

  pinMode(LUCI, INPUT_PULLUP);
  pinMode(FARI, INPUT_PULLUP);
  pinMode(BELL, INPUT_PULLUP);
  pinMode(GANCIO, INPUT_PULLUP);
  
  Serial.begin(9600);

  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS); // la più performante
  radio.setPALevel(RF24_PA_MIN);
  //radio.setPALevel(RF24_PA_MAX); // non usare con il piccolo
  radio.openWritingPipe(pipeOut); // il primo indirizzo della matrice

}

void loop() {
  v_pot = analogRead(V_POT); // VRX
  // h_pot = analogRead(H_POT); // VRY

  // Avanti indietro altrimenti ferma
  if (v_pot >= 550) {
    dataTosend.direzione = 'A';                             // AVANTI
    dataTosend.speed = (byte)map(v_pot, 550, 1023, 1, 255); // velocità
  } else if (v_pot <= 450) {
    dataTosend.direzione = 'I';                          // INDIETRO
    dataTosend.speed = (byte)map(v_pot, 450, 0, 1, 255); // velocità
  } else {
    dataTosend.direzione = 'S'; // STOP
    dataTosend.speed = 0x00;    // Speed
  }

  // Se non è un dataTosend.servo modificare
  h_pot = analogRead(H_POT); // VRY
  // alza e abbassa pala altrimenti pozizione di riposo
	if (h_pot >= 550) {										// ALZA LA PALA
		dataTosend.sterzo = (byte) map(h_pot, 550, 1023, 89, 0);	// da definire
	}
	else if (h_pot <= 450) {
		dataTosend.sterzo = (byte) map(h_pot, 450, 0, 91, 180);		// da definire
	}
	else {
		dataTosend.sterzo = (byte) 90;  			// posizione di riposo da definire
	}


  // tool fari lampeggiator & C
 aux = 0x00;

if(digitalRead (LUCI) == 0){
 aux =aux | 0x10;
}
if(digitalRead (FARI) == 0){
 aux =aux | 0x20;
}
if(digitalRead (BELL) == 0){
 aux =aux | 0x40;
}
if(digitalRead (GANCIO) == 0){
aux =aux | 0x80;
}
dataTosend.Tool = aux;

  radio.write(&dataTosend, sizeof(dataTosend));
  /* 
  //per debug
  Serial.print(dataTosend.direzione);
  Serial.print("   ");
  Serial.print(dataTosend.speed);
  Serial.print("   ");
  Serial.print(dataTosend.sterzo);
  Serial.print("   ");
  Serial.println(dataTosend.Tool);
  delay(1000);
   */
}

But the platformio.ini you provided before does not contain lib_deps!

If you are using a different platformio.ini for this project, please show this as well.

Otherwise, please name the source(s) of the libraries used and show how you have integrated them into your project.

![image|600x500](upload://1SMBqGmxUlXjSAew0ZmKB8g47N

I hope it is ok. I would send the complete zip folder to you, it should be more easy to check, but i do not know how is it possile

Unfortunately, the upload of your image did not work.

You can host your code in a GitHub repository, or use Google Drive or similar file hosters.

Please provide the smallest possible example that allows to reproduce the error.

Ok Those are the libtraries. The project was just to test the boar NRF24L01 so I have just made the main file, added the the libraries completed the ini file no more, What I am not able to understand is why with an ATMEL328p the compiler is not claiming. I have upload the project and all was OK. Changing the CPU the compiler is claiming agaist the same library of before that, by the way, is in in arduino core. I have made the same project with copy and paste on the old PC with win7 and ATMEL STUDIO7 with no problem . The PC is Dell Inspiron with Windows 11 Home

Make sure you are using a library for the correct architecture (AVR)

Where do the libraries from the lib directory come from?
There is no lib_deps section in your (again modified) platformio.ini.

tyname=RF24
version=1.4.6
author=TMRh20
maintainer=TMRh20,Avamander
sentence=Radio driver, OSI layer 2 library for nrf24L01(+) modules.
paragraph=Core library for nRF24L01(+) communication. Simple to use for beginners, but offers advanced configuration options. Many examples are included to demonstrate various modes of communication.
category=Communication
url=https://nRF24.github.io/RF24/
architectures=*
pe or paste code here

ok butb let me stress again. Project open exactly the same enviroment just the ini file without "board_build mcu = atmega328pb " the result is:

t#include "RF24.h"
#include <Arduino.h>
#Linking .pio\build\nanoatmega328\firmware.elf
Checking size .pio\build\nanoatmega328\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  10.9% (used 223 bytes from 2048 bytes)
Flash: [=         ]  12.9% (used 3952 bytes from 30720 bytes)
Building .pio\build\nanoatmega328\firmware.hex
========================================================================== [SUCCESS] Took 2.54 secondype or paste code here

Then adding to the file ini "board_build mcu = atmega328pb " comes up problems
with library. In one of the two istances should be something not working

Ok that’s this library in the registry:

If you use lib_deps = nrf24/RF24@^1.4.8 in your platformio.ini the library will be installed automatically. Delete the manual installed library inside the lib folder

That’s wrong. It must be board = atmega328pb

So here is everyhing you need:

platformio.ini:

[env:atmega328pb]
platform = atmelavr
board = atmega328pb
framework = arduino
lib_deps = nrf24/RF24@^1.4.8

main.cpp:

#include <Arduino.h>
#include <RF24.h>

#define LUCI 4
#define BELL 5
#define FARI 6
#define GANCIO 7
#define CE_PIN 8
#define CSN_PIN 9
#define H_POT A6
#define V_POT A7

byte aux = 0;
int h_pot = 0;
int v_pot = 0;

struct dataStruct
{
  char direzione;
  byte speed;
  byte sterzo;
  byte Tool;
} dataTosend;

RF24 radio(CE_PIN, CSN_PIN);             // Creo radio e definisco i pin
const uint64_t pipeOut = 0xE8E8F0F0E1LL; //  indirizzo dello slave

void setup()
{

  pinMode(LUCI, INPUT_PULLUP);
  pinMode(FARI, INPUT_PULLUP);
  pinMode(BELL, INPUT_PULLUP);
  pinMode(GANCIO, INPUT_PULLUP);

  Serial.begin(9600);

  radio.begin();
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS); // la più performante
  radio.setPALevel(RF24_PA_MIN);
  // radio.setPALevel(RF24_PA_MAX); // non usare con il piccolo
  radio.openWritingPipe(pipeOut); // il primo indirizzo della matrice
}

void loop()
{
  v_pot = analogRead(V_POT); // VRX
  // h_pot = analogRead(H_POT); // VRY

  // Avanti indietro altrimenti ferma
  if (v_pot >= 550)
  {
    dataTosend.direzione = 'A';                             // AVANTI
    dataTosend.speed = (byte)map(v_pot, 550, 1023, 1, 255); // velocità
  }
  else if (v_pot <= 450)
  {
    dataTosend.direzione = 'I';                          // INDIETRO
    dataTosend.speed = (byte)map(v_pot, 450, 0, 1, 255); // velocità
  }
  else
  {
    dataTosend.direzione = 'S'; // STOP
    dataTosend.speed = 0x00;    // Speed
  }

  // Se non è un dataTosend.servo modificare
  h_pot = analogRead(H_POT); // VRY
                             // alza e abbassa pala altrimenti pozizione di riposo
  if (h_pot >= 550)
  {                                                         // ALZA LA PALA
    dataTosend.sterzo = (byte)map(h_pot, 550, 1023, 89, 0); // da definire
  }
  else if (h_pot <= 450)
  {
    dataTosend.sterzo = (byte)map(h_pot, 450, 0, 91, 180); // da definire
  }
  else
  {
    dataTosend.sterzo = (byte)90; // posizione di riposo da definire
  }

  // tool fari lampeggiator & C
  aux = 0x00;

  if (digitalRead(LUCI) == 0)
  {
    aux = aux | 0x10;
  }
  if (digitalRead(FARI) == 0)
  {
    aux = aux | 0x20;
  }
  if (digitalRead(BELL) == 0)
  {
    aux = aux | 0x40;
  }
  if (digitalRead(GANCIO) == 0)
  {
    aux = aux | 0x80;
  }
  dataTosend.Tool = aux;

  radio.write(&dataTosend, sizeof(dataTosend));
  /*
  //per debug
  Serial.print(dataTosend.direzione);
  Serial.print("   ");
  Serial.print(dataTosend.speed);
  Serial.print("   ");
  Serial.print(dataTosend.sterzo);
  Serial.print("   ");
  Serial.println(dataTosend.Tool);
  delay(1000);
   */
}

result:

Processing atmega328pb (platform: atmelavr; board: atmega328pb; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/atmega328pb.html
PLATFORM: Atmel AVR (4.0.1) > ATmega328PB
HARDWARE: ATMEGA328PB 16MHz, 2KB RAM, 32KB Flash
PACKAGES:
 - framework-arduino-avr-minicore @ 2.1.3
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
Dependency Graph
|-- RF24 @ 1.4.8
Building in release mode
Checking size .pio\build\atmega328pb\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  10.8% (used 221 bytes from 2048 bytes)
Flash: [=         ]  12.5% (used 4042 bytes from 32256 bytes)
================================================================================= [SUCCESS] Took 1.23 seconds =================================================================================

OK Now I know the reason why. Thank for help

Sorry I am back again. I tried to upload the program I have tried on two different board the result is the same.

Uploading .pio\build\atmega328pb\firmware.hex
avrdude warning: USB device with VID: 0x03eb and PID: 0x2141 not found

I have only compiled because I don’t have an atmega328pb.
Have you tried the additional settings you already mentioned?

upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb

I am always using Atmel device to program and up today I had no problem.
I report some tests I made on the same boards (2) hoping they are of some interest.

  1. Old PC Atmel studio7 device signature 0x1E9516

PlatformIO  ini file
[env:nanoatmega328new]						
platform = atmelavr
board = nanoatmega328
framework = arduino
lib_deps = nrf24/RF24@^1.4.8
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb

avrdude: Device signature = 0x1e9516 (probably m328pb)
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.
Ini File
[env:atmega328pb]
platform = atmelavr
board = atmega328pb
framework = arduino
lib_deps = nrf24/RF24@^1.4.8
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb

Uploading .pio\build\atmega328pb\firmware.hex
avrdude warning: USB device with VID: 0x03eb and PID: 0x2141 not found

On the test 2 the system has recognized the boad and cpu correctly different story on test 3.

By the way it seems that is possible to program the board overriding the check using -F but I was not able to discover how.

Unfortunately, I’m out at this point as I don’t have any hardware to test.
Perhaps there is someone here who is more familiar with this.

Do not worry. Thank again