Just working on my AST CAN485 board. The interrupt does not work . Have simple code . Just cannot get the led to blink , it’s Led is On . Nothing happen when I ground the pin 9. Have tried pin 6,7 & 8 still no action.
Unless you have an external pullup, you need to turn on pullups on your input pin (otherwise, it will stay low or at least vary between 0 when grounded and possibly 1 depending on noise picked up by the lead). Try adding
Could you update your sketch to open the serial port and display the value of EXTERNAL_NUM_INTERRUPTS and let me know the result? I’ve got an idea, but I don’t have one of these boards to test the theory myself.
Note that in order to accomplish the request in my previous post, you’ll need to include wiring_private.h so that that macro will be defined in local scope.
Ok, I did some experimenting this afternoon and I think I know what your issue is. The AST-CAN485 uses an AT90CAN128 processor, so when compiling your sketch the macro AVR_AT90CAN128 gets defined. Unfortunately, when wiring_private.h gets included, this causes EXTERNAL_NUM_INTERRUPTS to be defined as 2 instead of 8 as expected. In the function attachInterrupt() a check is made so ensure that the interrupt number argument passed in is less than EXTERNAL_NUM_INTERRUPTS. If it is then the interrupt is enabled and the callback function is stored so it can be called when the interrupt occurs. In your case, the interrupt number is 7 since you’re trying to use pin 9, but since EXTERNAL_NUM_INTERRUPTS is being incorrectly defined as 2, the interrupt never gets enabled. To solve the issue, add AVR_AT90CAN128 as an additional check for defining EXTERNAL_NUM_INTERRUPTS as 8 in wiring_private.h (see code below).
Did find the a wiring_private.h file. sitting Arduino-hardware but in the Documents\Arduino\hardware\LeoStickBoardProfile-master. Not for AST-CAN485. But include the statement (AVR_AT90CAN128 )
Good morning, Devan. The file wiring_private.h gets included when WInterrupts.c gets compiled which is where the attachInterrupt() function is defined. On my computer (Windows 10 machine) both of these files are located at <Arduino_install_directory>\hardware\arduino\avr\cores\arduino. I think if you do a file search starting where the Arduino IDE is installed on your machine, you should be able to find it. I hope that helps.
Seem the file location of my Arduino Window App program. So I have clean up my Arduino IDE and installed classic Arduino IDE 1.8.12. Located wiring_private.h and added
|| defined(AVR_AT90CAN128).
My original code did work but this code work.
const int buttonPin = 9; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
volatile int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
// Attach an interrupt to the ISR vector
attachInterrupt(0, pin_ISR, CHANGE);
}
void loop() {
// Nothing here!
}
void pin_ISR() {
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, buttonState);
}
But still stumped it works on any ButtonPin selected how??
with k ranging from 0 to 7. If it works for 0 and 1 but not 2-7, then it means your update to wiring_private.h did not accomplish what it was intended to.