Smithfield, Rhode Island
Offline
God Member
Karma: 2
Posts: 825
|
 |
« on: August 31, 2011, 09:40:13 pm » |
Hi All... Okay I have tried a bunch of variations on this. This should be simple. I'm trying to get pin 19 to trigger an interrupt that toggles a LED on or off. I read this document: http://www.me.ucsb.edu/~me170c/Code/How_to_Enable_Interrupts_on_ANY_pin.pdfThat seemed to cover it reasonably well, but I still can't get it to work. The MPU is a 1284P. Physical pin 22 is Arduino pin 19, which is PCINT19, PCIE2 and PCMSK2. Did i make a simple mistake or did I totally screw this up? bool volatile state = 1;
ISR(PCINT2_void) { if(state) state = false; else state = true; }
void setup() { // establish interrupt processing / ISR PCICR |= (1<<PCIE2); PCMSK2 |= (1<<PCINT19); MCUCR = (1<<ISC01);
pinMode(19, OUTPUT); // Set LED on this pin for output pinMode(7, OUTPUT); }
void loop() { while(1) { if(state) digitalWrite(7, HIGH); else digitalWrite(7, LOW); } }
|
|
|
|
« Last Edit: September 01, 2011, 02:10:54 am by skyjumper »
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 6
Posts: 399
|
 |
« Reply #1 on: August 31, 2011, 10:56:55 pm » |
Do I understand correctly, you want the variable state to change whenever there is a pin change on pin 19?
If so, wouldn't pin 19 need to be an input?
|
|
|
|
|
Logged
|
|
|
|
|
"The old Europe"
Offline
Edison Member
Karma: 0
Posts: 2003
Bootloaders suck!
|
 |
« Reply #2 on: August 31, 2011, 11:00:09 pm » |
PCINT2_void That looks suspicious.
|
|
|
|
|
Logged
|
• Upload doesn't work? Do a loop-back test. • There's absolutely NO excuse for not having an ISP! • Your AVR needs a brain surgery? Use the online FUSE calculator. • My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets... • Microsoft is not the answer. It is the question, and the answer is NO!
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25517
Solder is electric glue
|
 |
« Reply #3 on: August 31, 2011, 11:54:36 pm » |
This project uses pin change interrupts, look at the code for an example of how to use them:- http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html
|
|
|
|
|
Logged
|
|
|
|
|
Smithfield, Rhode Island
Offline
God Member
Karma: 2
Posts: 825
|
 |
« Reply #4 on: September 01, 2011, 12:22:31 am » |
Do I understand correctly, you want the variable state to change whenever there is a pin change on pin 19?
If so, wouldn't pin 19 need to be an input?
I thought so too, but the examples seem to show it set as an output.
|
|
|
|
|
Logged
|
|
|
|
|
Smithfield, Rhode Island
Offline
God Member
Karma: 2
Posts: 825
|
 |
« Reply #5 on: September 01, 2011, 02:10:36 am » |
Got it working, code below... You guys caught the issues. PinMode does need to be set to INPUT, and the _void was supposed to be _vect. I can take some solace that it was wrong in the tutorial ;-) Thanks everyone! bool volatile state = 1;
ISR(PCINT2_vect) { if(state) state = false; else state = true; }
void setup() { // establish interrupt processing / ISR PCICR |= (1<<PCIE2); PCMSK2 |= (1<<PCINT19); MCUCR = (1<<ISC01);
pinMode(19, INPUT); // Ser LED on this pin for output pinMode(7, OUTPUT); }
void loop() { while(1) { if(state) digitalWrite(7, HIGH); else digitalWrite(7, LOW); } }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 249
Posts: 16541
Available for Design & Build services
|
 |
« Reply #6 on: September 01, 2011, 02:29:34 am » |
That's all it takes? Damn!
I'm keeping a copy of that handy! I couldn't get the examples I found to work when I was tryng that in January.
|
|
|
|
|
Logged
|
|
|
|
|
Smithfield, Rhode Island
Offline
God Member
Karma: 2
Posts: 825
|
 |
« Reply #7 on: September 01, 2011, 04:12:09 am » |
Hi Bob! Hey I have been planning to email you to see how well you weathered the hurricane! We lost that big pair tree in the front yard, which disappointed Kelly. I planted that for her when we moved in 14 years ago. Other that that, no damage.
As for the ISR, just so everyone who reads this later knows, the trick is knowing what to set those registers to. It varies from one MPU to another. And anyone who uses that example should be warned that the button is not debounced, so you'll see funny stuff if you have a dirty switch (like say, a bent paperclip). Of course this is just a little code to get pin change interrupts working. I didn't actually need to switch the LED on and off. ;-)
The next test was that I added code on the loop(){} method to pull pin 19 low then high and yup, it triggered the ISR. So that's good.
Now, if I could just get that UART to trigger an interrupt I would be home free! If I pull pin 2 down with a digitalWrite() I can trigger it. But hey, progress is being made...
|
|
|
|
« Last Edit: September 01, 2011, 04:16:02 am by skyjumper »
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 249
Posts: 16541
Available for Design & Build services
|
 |
« Reply #8 on: September 01, 2011, 06:49:09 pm » |
That's too bad about tree. We just had a mostly dead small tree fall over, and lost power Sunday morning until 2AM Monday.
Are you setting up softare interrupts with Xon/Xoff characters beng received, or creating and RHR interrupt when so many characters are received? See 7.3.1, 7.5, and 8.3, 8.4, 8.12 of the SC16IS752 data sheet.
|
|
|
|
|
Logged
|
|
|
|
|
Smithfield, Rhode Island
Offline
God Member
Karma: 2
Posts: 825
|
 |
« Reply #9 on: September 01, 2011, 07:27:09 pm » |
That's too bad about tree. We just had a mostly dead small tree fall over, and lost power Sunday morning until 2AM Monday.
Are you setting up softare interrupts with Xon/Xoff characters beng received, or creating and RHR interrupt when so many characters are received? See 7.3.1, 7.5, and 8.3, 8.4, 8.12 of the SC16IS752 data sheet.
Well that's one way to get rid of a dead tree! I set the trigger on the RHR to trigger I think after 48 characters. I don't recall exactly what the number was but I do recall setting it. I didn't look at the Xon/Xoff stuff because I have none of that, just the two data lines. I'll look the data sheet over again tonight to see if I need to do something with that even though those lines are not wired. Thanks...
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Online
Brattain Member
Karma: 249
Posts: 16541
Available for Design & Build services
|
 |
« Reply #10 on: September 01, 2011, 07:36:51 pm » |
Xon/Xoff are not lines, they are control characters you would put in the message, the UART would look for them coming in. Seems like you have set some bits in a couple of registers too for either type of interrupt. If you can make PCINTs work, I am sure you can get there with this one 
|
|
|
|
|
Logged
|
|
|
|
|
Smithfield, Rhode Island
Offline
God Member
Karma: 2
Posts: 825
|
 |
« Reply #11 on: September 01, 2011, 07:49:24 pm » |
If you can make PCINTs work, I am sure you can get there with this one  Fingers crossed! I'll be back late tonight to fight with it.
|
|
|
|
|
Logged
|
|
|
|
|
|