| Author |
Message |
|
|
Posted: Apr 14, 2012 - 09:14 AM |
|

Joined: Aug 06, 2011
Posts: 4
|
|
Hi All,
Been reading a fair bit and i still cant work out this interrupt thing. can someone tell me what im doing wrong?
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
ISR(PCINT1_vect) {
PORTB = 0xFF;
}
int main(void)
{
DDRB = 0xFF;
PCICR = (1<<PCIE1);
PCMSK1 = (1<<PCINT12);
sei();
while(1)
{
}
}
I have an LED attached to PORTB and im giving PCINT12 (PD5) +5v via a resistor. Im expecting the LED to turn on but nothing is happening.
Thanks
millers |
|
|
| |
|
|
|
|
|
Posted: Apr 14, 2012 - 02:52 PM |
|


Joined: Jul 18, 2005
Posts: 62324
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
| I don't have easy access to a datasheet (iPad) but on the surface your code looks right to me. What happens if you forget the interrupt but just try to light (better, flash) the LED? |
_________________
|
| |
|
|
|
|
|
Posted: Apr 14, 2012 - 03:26 PM |
|


Joined: Feb 19, 2001
Posts: 25921
Location: Wisconsin USA
|
|
|
Quote:
I have an LED attached to PORTB and im giving PCINT12 (PD5) +5v via a resistor.
Where is the pin-CHANGE part in this?
(Also, how are the LED(s) connected? You might want to toggle it/them in the ISR.) |
|
|
| |
|
|
|
|
|
Posted: Apr 16, 2012 - 07:20 AM |
|

Joined: Aug 06, 2011
Posts: 4
|
|
|
theusch wrote:
Where is the pin-CHANGE part in this?
(Also, how are the LED(s) connected? You might want to toggle it/them in the ISR.)
sorry, the pin change part is connecting/disconnecting the +5v. from what i can work out this should fire the ISR once when i connect it and once when i disconnect it?
the LED is connected PB1 -> resistor -> LED -> ground. if i connect +5v to the resistor instead of powering from PB1 the LED does light.
if i just switch on PORTB in the main code instead of using the ISR the LED does light up
edit: do i have to set the data direction register for PORTD to use PCINT12? |
|
|
| |
|
|
|
|
|
Posted: Apr 16, 2012 - 10:22 AM |
|


Joined: Jul 18, 2005
Posts: 62324
Location: (using avr-gcc in) Finchingfield, Essex, England
|
|
|
Quote:
. from what i can work out this should fire the ISR once when i connect it and once when i disconnect it?
Given that the ISR appears to turn on the LED and nothing else would ever then turn it off again how can you possibly know whether you have had one interrupt, two interrupts or three thousand two hundred and thirty seven interrupts?
(if you are just touching the pin with a wire you are bound to get bounce and far more than just 2 interrupts anyway!) |
_________________
|
| |
|
|
|
|
|
Posted: Apr 17, 2012 - 07:16 AM |
|

Joined: Aug 06, 2011
Posts: 4
|
|
| its just a proof of concept at the moment. eventually the interrupt will increment a count that will be checked by a timer. the problem is the light never turns on. if it did then I could see it working and move onto integrating it with the rest of the project |
|
|
| |
|
|
|
|
|
Posted: Apr 18, 2012 - 03:00 AM |
|

Joined: Aug 06, 2011
Posts: 4
|
|
this is now resolved
the code is perfect but the PD5 pin i was trying to use was floating high so giving it +5v was not triggering a change. pulling it to ground causes the ISR to fire as expected |
|
|
| |
|
|
|
|
|