Sketch compiles and works on Arduino Micro but won't compile for ATmega32A

Hi All

I have been working on a project for a servo and relay controller which I have got fully working using an Arduino Micro and all the little bugs have been ironed out . I'm now at the stage of wanting to get a few PCB's produced for this project which I plan on using ATmega32A IC's for. I have installed the MightyCore pack and have managed to use one of my UNO's to burn the Bootloader to the ATmega32A and then upload and run the blink sketch without any problems.

I have now changed the pin numbers in my sketch to match the ATmega32A and have included the MightyCore Servo library which automatically adds the MightyCore ServoTimers library but get the following error messages when compiling:

In file included from /Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/Servo.h:52:0,
                 from /Users/martinstewart/Documents/Arduino/ATmega32A_quad_servo_driver/ATmega32A_quad_servo_driver.ino:25:
/Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/ServoTimers.h:65:16: error: redeclaration of '_timer1'
 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
                ^~~~~~~
In file included from /Users/martinstewart/Documents/Arduino/ATmega32A_quad_servo_driver/ATmega32A_quad_servo_driver.ino:24:0:
/Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/ServoTimers.h:65:16: note: previous declaration 'timer16_Sequence_t _timer1'
 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
                ^~~~~~~
In file included from /Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/Servo.h:52:0,
                 from /Users/martinstewart/Documents/Arduino/ATmega32A_quad_servo_driver/ATmega32A_quad_servo_driver.ino:25:
/Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/ServoTimers.h:65:25: error: redeclaration of '_Nbr_16timers'
 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
                         ^~~~~~~~~~~~~
In file included from /Users/martinstewart/Documents/Arduino/ATmega32A_quad_servo_driver/ATmega32A_quad_servo_driver.ino:24:0:
/Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/ServoTimers.h:65:25: note: previous declaration 'timer16_Sequence_t _Nbr_16timers'
 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
                         ^~~~~~~~~~~~~
In file included from /Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/Servo.h:52:0,
                 from /Users/martinstewart/Documents/Arduino/ATmega32A_quad_servo_driver/ATmega32A_quad_servo_driver.ino:25:
/Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/ServoTimers.h:65:41: error: conflicting declaration 'typedef enum timer16_Sequence_t timer16_Sequence_t'
 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
                                         ^~~~~~~~~~~~~~~~~~
In file included from /Users/martinstewart/Documents/Arduino/ATmega32A_quad_servo_driver/ATmega32A_quad_servo_driver.ino:24:0:
/Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo/src/ServoTimers.h:65:41: note: previous declaration as 'typedef enum timer16_Sequence_t timer16_Sequence_t'
 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
                                         ^~~~~~~~~~~~~~~~~~
exit status 1
Error compiling for board ATmega32.

If I remove the ServoTimers library I get the following error messages:

/Users/martinstewart/Documents/Arduino/libraries/Servo/src/avr/Servo.cpp: In function 'void initISR(timer16_Sequence_t)':
/Users/martinstewart/Documents/Arduino/libraries/Servo/src/avr/Servo.cpp:136:5: error: 'TIFR1' was not declared in this scope
     TIFR1 |= _BV(OCF1A);     // clear any pending interrupts;
     ^~~~~
/Users/martinstewart/Documents/Arduino/libraries/Servo/src/avr/Servo.cpp:136:5: note: suggested alternative: 'TIFR'
     TIFR1 |= _BV(OCF1A);     // clear any pending interrupts;
     ^~~~~
     TIFR
/Users/martinstewart/Documents/Arduino/libraries/Servo/src/avr/Servo.cpp:137:5: error: 'TIMSK1' was not declared in this scope
     TIMSK1 |=  _BV(OCIE1A) ; // enable the output compare interrupt
     ^~~~~~
/Users/martinstewart/Documents/Arduino/libraries/Servo/src/avr/Servo.cpp:137:5: note: suggested alternative: 'TIMSK'
     TIMSK1 |=  _BV(OCIE1A) ; // enable the output compare interrupt
     ^~~~~~
     TIMSK
Multiple libraries were found for "Servo.h"
 Used: /Users/martinstewart/Documents/Arduino/libraries/Servo
 Not used: /private/var/folders/gj/jw9sq7c95qs_5r_kszfs0g9m0000gn/T/AppTranslocation/A6D84A38-6BF8-4890-8C2F-E7DB504B91B4/d/Arduino.app/Contents/Java/libraries/Servo
 Not used: /Users/martinstewart/Library/Arduino15/packages/MightyCore/hardware/avr/2.1.1/libraries/Servo
exit status 1
Error compiling for board ATmega32.

I've tried various other things like using the original Servo library which ran well on the Arduino Micro but I still get error messages and can't compile.

I'm fairly new to working with Arduino and coding so is there anything obvious I'm missing here or something I haven't tried?

I can show my original sketch if that helps but it's quite lengthy.

Many Thanks
Martin

the boards use different processors with different registers and symbols name

It looks like your sketch includes 'ServoTimers.h' on line 24 and includes 'Servo.h' on line 25. The file 'Servo.h' includes the file 'ServoTimers.h' on line 52 and ServoTimers.h is not protected against being included twice so everything defined in it is defined twice. Maybe taking out the 'ServoTimers.h' include on line 24 will fix it?

In file included from /Servo/src/Servo.h:52:0,
                      from ATmega32A_quad_servo_driver.ino:25:
In file included from ATmega32A_quad_servo_driver.ino:24:0:
                  /ServoTimers.h:65:16: note: previous declaration 'timer16_Sequence_t _timer1'
 typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;

Hi John

Thanks for your reply but this is something I have already tried which didn't work unfortunately.

Just before reading Greg's post above, I did read that the ATmega32 is an older chip and that I should try the ATmega324. I removed ServoTimers.h from my sketch and compiled for the ATmega324 which seems to work. I have now ordered a few 324 chips to try on the breadboard.

Thanks for your help guys
Martin

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.