Any help would be appreciated. I am using an Arduino Micro. The below code works fine:
#include <TMC2209.h>
HardwareSerial & serial_stream = Serial1;
const long SERIAL_BAUD_RATE = 115200;
const int DELAY = 3000;
// Instantiate TMC2209
TMC2209 stepper_driver;
#define LED 15
#define input_pin 11
volatile bool inputChanged = false;
void setup()
{
Serial.begin(SERIAL_BAUD_RATE);
stepper_driver.setup(serial_stream);
pinMode(LED, OUTPUT);
pinMode(input_pin, INPUT);
digitalWrite(LED, LOW);
// Set up PCINT for pins PCINT0-7
PCICR |= B00000001; // Enable PCIE0 (PCINT0-7 interrupt)
PCMSK0 |= B10000000; //PCINT7)
sei();
}
void loop()
{
if (stepper_driver.isSetupAndCommunicating())
{
Serial.println("Stepper driver is setup and communicating!");
Serial.println("Try turning driver power off to see what happens.");
}
else if (stepper_driver.isCommunicatingButNotSetup())
{
Serial.println("Stepper driver is communicating but not setup!");
Serial.println("Running setup again...");
stepper_driver.setup(serial_stream);
}
else
{
Serial.println("Stepper driver is not communicating!");
Serial.println("Try turning driver power on to see what happens.");
}
Serial.println();
delay(DELAY);
if (inputChanged) {
// Toggle LED state
digitalWrite(LED, digitalRead(LED) == HIGH ? LOW : HIGH);
inputChanged = false; // Reset the flag
}
// Delay to debounce and visibly see the LED state change, if needed
// delay(100);
}
But when I add the ISR to the code I get the "multiple definition of `__vector_9'" error and it fails to compile. Here is the code with the ISR:
#include <TMC2209.h>
HardwareSerial & serial_stream = Serial1;
const long SERIAL_BAUD_RATE = 115200;
const int DELAY = 3000;
// Instantiate TMC2209
TMC2209 stepper_driver;
#define LED 15
#define input_pin 11
volatile bool inputChanged = false;
void setup()
{
Serial.begin(SERIAL_BAUD_RATE);
stepper_driver.setup(serial_stream);
pinMode(LED, OUTPUT);
pinMode(input_pin, INPUT);
digitalWrite(LED, LOW);
// Set up PCINT for pins PCINT0-7
PCICR |= B00000001; // Enable PCIE0 (PCINT0-7 interrupt)
PCMSK0 |= B10000000; //PCINT7)
sei();
}
void loop()
{
if (stepper_driver.isSetupAndCommunicating())
{
Serial.println("Stepper driver is setup and communicating!");
Serial.println("Try turning driver power off to see what happens.");
}
else if (stepper_driver.isCommunicatingButNotSetup())
{
Serial.println("Stepper driver is communicating but not setup!");
Serial.println("Running setup again...");
stepper_driver.setup(serial_stream);
}
else
{
Serial.println("Stepper driver is not communicating!");
Serial.println("Try turning driver power on to see what happens.");
}
Serial.println();
delay(DELAY);
if (inputChanged) {
// Toggle LED state
digitalWrite(LED, digitalRead(LED) == HIGH ? LOW : HIGH);
inputChanged = false; // Reset the flag
}
// Delay to debounce and visibly see the LED state change, if needed
// delay(100);
}
ISR(PCINT0_vect) {
// ISR for pin change interrupt for PCINT7
inputChanged = true; // Simply flag that input has changed
}
It's possible that adding the PCINT0 would conflict with a software serial use of interrupt vector 10. I would think more basic issue with software serial and interrupt vectors should be present even before you add the pin change interrupt vector.
Can you link to the specific library you are using for the 2209?
I am using the TMC2209.h library to configure 4 TMC driver ICs via the hardware UART port of the Arduino Micro. I want to use pin change interrupts to flag when each IC driver detects a motor stall.
You are correct. I updated the core file as stated and it compiles successfully, but now the com port is acting squirrely when I try to upload code:
Sketch uses 7456 bytes (26%) of program storage space. Maximum is 28672 bytes.
Global variables use 612 bytes (23%) of dynamic memory, leaving 1948 bytes for local variables. Maximum is 2560 bytes.
avrdude: ser_open(): can't set com-state for "\.\COM4"
Failed uploading: uploading error: exit status 1