Compiling issues between Nano and Nano every

Hi,

I wrote a long program that compiles well on Arduino Uno and Arduino Nano but while compiling for Arduino Nano Every I get a bunch ohh error messages. I don't understand why, nor where to search for the issues to solve.

Error Messages :

Arduino: 1.8.10 (Mac OS X), Board: "Arduino Nano Every, None (ATMEGA4809)"

In file included from /Users/marc/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/io.h:99:0,
from /Users/marc/Library/Arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/avr/include/avr/pgmspace.h:90,
from /Users/marc/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/String.h:30,
from /Users/marc/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Print.h:24,
from /Users/marc/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Stream.h:25,
from /Users/marc/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/Client.h:22,
from /Users/marc/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/api/ArduinoAPI.h:29,
from /Users/marc/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.5/cores/arduino/Arduino.h:23,
from /Users/marc/Documents/Arduino/libraries/DS3231/DS3231.h:26,
from /Users/marc/Documents/Arduino/libraries/DS3231/DS3231.cpp:22:
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h: In member function 'void DS3231::begin()':
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:7: error: 'TWSR' was not declared in this scope
cbi(TWSR, TWPS0);
^
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS0);
^~~
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:7: note: suggested alternative: 'TWI0'
cbi(TWSR, TWPS0);
^
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS0);
^~~
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:13: error: 'TWPS0' was not declared in this scope
cbi(TWSR, TWPS0);
^
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS0);
^~~
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:13: note: suggested alternative: 'TWI0'
cbi(TWSR, TWPS0);
^
/Users/marc/Documents/Arduino/libraries/DS3231/hardware/avr/HW_AVR.h:12:3: note: in expansion of macro 'cbi'
cbi(TWSR, TWPS0);
^~~

....and many ,more.

Error compiling for board Arduino Nano Every.

did you try the 328p compatibility setting?

The 328p compability mode does not help here, it emulates only PORTx and DDRx registers.

Is there a difference in programming language between Nano and Nano every ?

ArduinoLux:
Is there a difference in programming language between Nano and Nano every ?

The programming language is the same, ie C++, but as the two boards use different processors expect them to have different register names. This will cause problems when code tries to access registers that do not exist

UKHeliBob:
The programming language is the same, ie C++, but as the two boards use different processors expect them to have different register names. This will cause problems when code tries to access registers that do not exist

they use the same AVR processor, but with different MCU peripherals

Juraj:
they use the same AVR processor, but with different MCU peripherals

Arduino Nano Every — Arduino Official Store says it is

Based on the ATMega4809 AVR processor

Is that the same as the Atmega328 ?

UKHeliBob:
Arduino Nano Every — Arduino Official Store says it is
Is that the same as the Atmega328 ?

if you now it is the same AVR CPU, you know you can compile and link with the same avr-gcc because it has the same binary code.
if you know it has different peripherals you know you can't use code which uses peripheral registers of the 328p or other classic Atmel AVR MCUs. The classic Atmel AVR based MCUs had the same selection of peripherals, in a different 'mix'. The 4809 and co. have very different peripherals. yes there are pins, timers, spi, i2c ... but they work different

Sorry, but I don't know what you mean by different peripherals in this context. Can you please explain ?

UKHeliBob:
Sorry, but I don't know what you mean by different peripherals in this context. Can you please explain ?

from the datasheets

4809
Peripherals:
– One 16-bit Timer/Counter type A (TCA) with a dedicated period register and three compare channels
– Up to four 16-bit Timer/Counter type B (TCB) with input capture
– One 16-bit Real-Time Counter (RTC) running from an external crystal or an internal RC oscillator
– Up to four USARTs with fractional baud rate generator, auto-baud, and start-of-frame detection
– Master/slave Serial Peripheral Interface (SPI)
– Master/slave TWI with dual address match• Can operate simultaneously as master and slave• Standard mode (Sm, 100 kHz)• Fast mode (Fm, 400 kHz)• Fast mode plus (Fm+, 1 MHz)
– Event System for core independent and predictable inter-peripheral signaling
– Configurable Custom Logic (CCL) with up to four programmable Look-up Tables (LUT)
– One Analog Comparator (AC) with a scalable reference input
– One 10-bit 150 ksps Analog-to-Digital Converter (ADC)
– Five selectable internal voltage references: 0.55V, 1.1V, 1.5V, 2.5V, and 4.3V
– CRC code memory scan hardware• Optional automatic CRC scan before code execution is allowed
– Watchdog Timer (WDT) with Window mode, with a separate on-chip oscillator
– External interrupt on all general purpose pins

328p
peripheral features
●Two 8-bit Timer/Counters with separate prescaler and compare mode
●One 16-bit Timer/Counter with separate prescaler, compare mode, and capture mode
●Real time counter with separate oscillator
●Six PWM channels
●8-channel 10-bit ADC in TQFP and QFN/MLF package
●Temperature measurement
●Programmable serial USART
●Master/slave SPI serial interface
●Byte-oriented 2-wire serial interface (Phillips I2C compatible)
●Programmable watchdog timer with separate on-chip oscillator
●On-chip analog comparator
●Interrupt and wake-up on pin change

for example. interrupt on 4809

An interrupt must be initialized in the following order:

  1. Configure the CPUINT if the default configuration is not adequate (optional):
    – Vector handling is configured by writing to the respective bits (IVSEL and CVT) in the Control A register(CPUINT.CTRLA).
    – Vector prioritizing by round robin is enabled by writing a '1' to the Round Robin Priority Enable bit(LVL0RR) in CPUINT.CTRLA.
    – Select the priority level 1 vector by writing its address to the Interrupt Vector (LVL1VEC) in the Level 1Priority register (CPUINT.LVL1VEC).
  2. Configure the interrupt conditions within the peripheral, and enable the peripheral's interrupt.
  3. Enable interrupts globally by writing a '1' to the Global Interrupt Enable bit (I) in the CPU Status register(CPU.SREG)

ATmega 328p: The external interrupt 1 is activated by the external pin INT1 if the SREG I-flag and the corresponding interrupt mask are set.The level and edges on the external INT1 pin that activate the interrupt are defined in Table 12-1.

To my mind, it is very disingenuous to differentiate between the two processors based on their peripheral features. How many angels are there on the head of the AVR pin ?

UKHeliBob:
To my mind, it is very disingenuous to differentiate between the two processors based on their peripheral features. How many angels are there on the head of the AVR pin ?

that is the problem. AVR doesn't have pins. it is a CPU.

Atmel SAM MCUs on Due, Zero, MKR; STM32 MCUs in BluePill and Maple, nRF5 MCUs on Nano BLE. NXP MCUs on Teensy;... all use ARM CPU. they use the same compiler, but again the peripherals are configured very differently

Atmel SAM MCUs on Due, Zero, MKR; STM32 MCUs in BluePill and Maple, nRF5 MCUs on Nano BLE. NXP MCUs on Teensy;... all use ARM CPU.

An ARM CPU or the same CPU and what about the 328P ?

UKHeliBob:
An ARM CPU or the same CPU and what about the 328P ?

so OK ARM architecture is scalable, while AVR not (yet). so while I believe the AVR CPUs are same, the ARM CPUs in my list are different variants, but still the SAMD and nRF51 Cortex M0 ARM CPU versions are same but the peripherals are different