Hi, I am gradually making progress with my avr4809 baremetal encoder project. (which I previously coded in the Arduino IDE on a mega2560 board.
In the MegaCoreX github readme it says I can do the following to call an Interrupt
‘’’
Simply call attachInterrupt like this:
attachInterrupt(myPin, myInterruptFunction, RISING);
‘’’
so in my barebones project, my version of the above is as follows:
attachInterrupt(encoder_Pin,encoderInterrupt, RISING);
where encoder_Pin is defined in my .h file as at the bottom of this extract :
#include <avr/io.h>
#include <stdio.h>
#include <string.h>
#include <util/delay.h>
#include <stdlib.h>
#define F_CPU 3333333
#define USART1_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 * (float)BAUD_RATE)) + 0.5)
#define MAX_COMMAND_LEN 16
#define INIT_DELAY 10 // Delay to invalidate the after-reset noise on the PC0 pin (TX)
#define ASCOMSerial USART1 // give the USARTS meaningful names
#define MONITORSerial USART0 //this will be a ftdi
#define STEPPERSerial USART2 //this is serial to serial hardwired connectors
#define encoder_Pin PC2 // pin used for encoder interrupts
and an interrupt routine handling the encoder devices inputs, called ‘encoderInterrupt’ exists in my encoder.cpp file
I was a bit perplexed by the ’ ; ’ following the attachinterrupt statement as that obviously implies a function call.
So I’m guessing I’ve missed something, but don’t know what that is, so any help much appreciated. The errors from compilation are posted below:
Executing task: C:\Users\Paul\.platformio\penv\Scripts\platformio.exe run <
Processing ATmega4809_pyupdi_upload (platform: atmelmegaavr; board: ATmega4809; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelmegaavr/ATmega4809.html
PLATFORM: Atmel megaAVR (1.4.0) > ATmega4809
HARDWARE: ATMEGA4809 16MHz, 6KB RAM, 48KB Flash
PACKAGES:
- framework-arduino-megaavr-megacorex 1.0.7
- toolchain-atmelavr 2.70300.201015 (7.3.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 10 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <src>
Building in release mode
Compiling .pio\build\ATmega4809_pyupdi_upload\src\main.cpp.o
Archiving .pio\build\ATmega4809_pyupdi_upload\lib50d\libsrc.a
In file included from src\main.cpp:7:0:
src\main.cpp: In function 'int main()':
lib\src/encoder.h:23:21: error: 'PC2' was not declared in this scope
#define encoder_Pin PC2 // pin used for encoder interrupts
^
src\main.cpp:26:17: note: in expansion of macro 'encoder_Pin'
attachInterrupt(encoder_Pin,encoderInterrupt, RISING);
^~~~~~~~~~~
src\main.cpp:26:47: error: 'RISING' was not declared in this scope
attachInterrupt(encoder_Pin,encoderInterrupt, RISING);
^~~~~~
src\main.cpp:26:1: error: 'attachInterrupt' was not declared in this scope
attachInterrupt(encoder_Pin,encoderInterrupt, RISING);
^~~~~~~~~~~~~~~
src\main.cpp:26:1: note: suggested alternative: 'encoderInterrupt'
attachInterrupt(encoder_Pin,encoderInterrupt, RISING);
^~~~~~~~~~~~~~~
encoderInterrupt
*** [.pio\build\ATmega4809_pyupdi_upload\src\main.cpp.o] Error 1
================================================================================================== [FAILED] Took 0.79 seconds ==================================================================================================
The terminal process "C:\Users\Paul\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.
The compiler doesn’t like my encoder pin definition as PC2, but again from the MegaCoreX documentation, I understand I can do this and if I control click on PC2, I see the definition as chip pin 2, which is what I’d expect (it’s a 4809 40 pin DIP).
I could model the intterrupt as per Microchip’s TB3229 example - wake up on button press, and happy to do so if needs be, but the MegaCoreX readme’s explanation looks easy to use, so I thought I’d try that 1st and see what the code volume looks like.
thanks
Paul