Hello all,
My ISRs do not seem to be working properly. Hopefully, someone sees what i'm doing wrong ----No error messages, just incrementing isn't working!!!
The goal is to increment a scroll up or down function on a screen and reset the arduino.
My file is absolutely massive, so bits and pieces are shown. I have verified the signal lines are correctly read via serial monitoring.
Using an ATMega2560
volatile int Type = 1; //indicator for which type is selected
int ResetSignal = 26;
int Inc = 28;
int Dec = 29;
void(* resetFunc) (void) = 0;
void setup() {
//ESTABLISH PINS
pinMode(ResetSignal, INPUT);
pinMode(Inc, INPUT);
pinMode(Dec, INPUT);
attachInterrupt(digitalPinToInterrupt(Inc), ScrollUp, RISING);
attachInterrupt(digitalPinToInterrupt(Dec), ScrollDown, RISING);
attachInterrupt(digitalPinToInterrupt(ResetSignal), ArdReset, HIGH);
}
void loop(){
;
}
void ArdReset(){
resetFunc; //reset the arduino if PLC reset is pushed.
} //end reset functionality
void ScrollUp() {
if (Type < 2) {
Type = Type+ 1;
} else if (Type == 2) {
Type = 0;
}
}
void ScrollDown() {
if (Type > 0) {
Type = Type - 1;
} else if (Type == 0) {
Type = 2;
}
}
Thank you in advance!
PieterP
September 18, 2020, 7:42pm
2
Type = Type++;
That won't work, you increment the variable and then reset it to the old value.
You want:
++Type;
Pieter
If you knew what was wrong with the code you could fix it. But only if you knew what was wrong could you select the snippet to post.
If your code is massive than why have you not tested it before now?
Write a compleat program that illustrates your problem, make it as short as you can.
Advice for snippet posters is given here http://snippets-r-us.com
Grumpy_Mike:
If you knew what was wrong with the code you could fix it. But only if you knew what was wrong could you select the snippet to post.
If your code is massive than why have you not tested it before now?
Write a compleat program that illustrates your problem, make it as short as you can.
Advice for snippet posters is given here http://snippets-r-us.com
synthesized the 4 snippets for you.
Also, code has been tested up to the point of adding these ISRs.
void ArdReset(){
resetFunc; //reset the arduino if PLC reset is pushed.
}
What's that?
TheMemberFormerlyKnownAsAWOL:
void ArdReset(){
resetFunc; //reset the arduino if PLC reset is pushed.
}
What's that?
This is shown above setup
void(* resetFunc) (void) = 0;
reset vector at address 0
crude way of implementing a software reset
PieterP
September 18, 2020, 8:48pm
8
ci_jmasters:
This is shown above setup
void(* resetFunc) (void) = 0;
reset vector at address 0
crude way of implementing a software reset
That's not what he means, turn on your compiler warnings:
sketch: In function 'void ArdReset()':
sketch:4: warning: statement has no effect
resetFunc; //reset the arduino if PLC reset is pushed.
^
You are naming the function but not calling the function. Add "( )" after the name to call the function.
And since it is a pointer, it would make your intention clearer if you dereference the pointer explicitly:
(*resetFunc)( );
Hi all, the focus seems to have shifted....
for refence, I can and HAVE triggered the reset functionality outside of ISRs.
As soon as moved the code into this ISR format (using a volatile int and attach Interrupt).
I cannot get the Type number to increase or decrease, and cannot get reset to work.
Any thoughts as to why?
My thought: The commonalities between the three non-working functions are the formatting, the use of a volatile variable, and attachInterrupt. I reviewed the literature on these three and all seem correct at first glance..
int ResetSignal = 26;
int Inc = 28;
int Dec = 29;
void setup() {
attachInterrupt(digitalPinToInterrupt(Inc), ScrollUp, RISING);
attachInterrupt(digitalPinToInterrupt(Dec), ScrollDown, RISING);
attachInterrupt(digitalPinToInterrupt(ResetSignal), ArdReset, HIGH);
}
Using an ATMega2560
The pins you are using are not external interrupt pins on the Mega.
Mega, Mega2560, MegaADK
2, 3, 18, 19, 20, 21
Also vectoring through the reset pointer does not do the same thing as a hardware reset.