Problems with Pin Change Interrupts on a tiny841

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

 

I've run into a bit of a brick wall. I have a  UART connection to a GSM modem, and everything works great.

But I also need to enable a Pin Change Interrupt on PA5 (Not used for anything else but the interrupt).

The problem arrives when I try to set the PCINT5 bit in the PCMSK0 register.

 

First thing, the PCINT5 definition is not included, so no key word highlight in AVR studio 6.2

If I try:

 

PCMSK0 = (1 << PCINT5);

 

I get a :

 

Error    1    'PCINT5' undeclared (first use in this function)   

 

 

So I tried a more direct approach:

 

PCMSK0 = 0b00100000;

 

It compiles, but when I run the program, the UART and everything else stops working.

I comment out that line, and everything works again.

Any ideas on what I am doing wrong?

 

Thank you!

 

 

 

 

 

This topic has a solution.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd say we need a bit more context.  Ideally, a small, complete test program that demonstrates the symptoms.

 

If I had to make a guess, PCIE0 is set in GIMSK but there is no ISR for it, and the code is jumping to reset.  But that would only happen with activity on the pin.  Hmmm--perhaps at startup, if the initial value of the PIN register is 0 at reset but then if there is a high on that pin PCif0 GETS SET?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did a small test program:

(sorry I don't know why all the colores don't copy-paste correctly)

 

//defines

#define F_CPU 1843200UL

 

//includes

#include <avr/io.h>

#include <avr/interrupt.h>

#include <util/delay.h>

 

int main ( void )

{

    //UART0

    UCSR0A = (0 << RXC0) | (0 << TXC0) | (0 << UDRE0) | (0 << FE0) | (0 << DOR0) | (0 << UPE0) | (0 << U2X0) | (0 << MPCM0);

    UCSR0B = (1 << RXCIE0) | (0 << TXCIE0) | (0 << UDRIE0) | (1 << RXEN0) | (1 << TXEN0) | (0 << UCSZ02) | (0 << RXB80) | (0 << TXB80);

    UCSR0C = (0 << UMSEL01) | (0 << UMSEL00) | (0 << UPM01) | (0 << UPM00) | (0 << USBS0) | (1 << UCSZ01) | (1 << UCSZ00) | (0 << UCPOL0);

    UBRR0H = 0;

    UBRR0L = 47;

 

    PCMSK0 = 0b00100000;

   // PCMSK0 = (1 << PCINT5); //0b00100000;

    //PCMSK1 = 0b00000000;

    GIMSK = (0 << PCIE0);

 

 

    PRR = 0x00; // uart clock sorce

    sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processe

    

    while (1)                    //loop 

    {

        // Wait if a byte is being transmitted

        while((UCSR0A&(1<<UDRE0)) == 0) {};

        UDR0 = 0x21;

        _delay_ms(100);

    }

}

 

ISR(PCINT0_vect)

{

    _delay_ms(100);

}

 

On my terminal, I get a stream of ! IF i don't include the line:

PCMSK0 = 0b00100000;

 

Any ideas?

 

 

Last Edited: Tue. Sep 16, 2014 - 09:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any ideas?

Not really.  The posted code enables the RX interrupt but there is no handler.  Would that explain your symptoms?

 

Are you >>positive<< you are building for the correct AVR model?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, this is a small snippet of the code i working on (it does have a RX interrupt service handler) 

I didn´t place the exact code because its longgggg

I ran this small code and it does the same thing as the larger code:

The program stops sending messages via the UART when I wright to the PCMSK0.

 

Yes, I even looked into the iotn841.h and confirmed that the registers where the same as the data sheet, or at leas the first one, since the data sheet has a:

0x12 (0x32) address for the PCMSK0 resister and the .h has the 0x12.

 

 

Last Edited: Tue. Sep 16, 2014 - 09:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You >>did<< really paste the REAL code for your test program?

 

Are there any warnings, especially "misspelled"? 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

this is the output form AVR studio 6.2, hope it helps

 

------ Build started: Project: Test, Configuration: Debug AVR ------

Build started.

Project "Test.cppproj" (default targets):

Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').

Target "CoreBuild" in file "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Compiler.targets" from project "C:\Users\Roy\Desktop\Test\Test.cppproj" (target "Build" depends on it):

    Task "RunCompilerTask"

        Shell Utils Path C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils

        C:\Program Files\Atmel\Atmel Studio 6.2\shellUtils\make.exe all 

        make: Nothing to be done for `all'.

    Done executing task "RunCompilerTask".

    Task "RunOutputFileVerifyTask"

                Program Memory Usage     :    158 bytes   1.9 % Full

                Data Memory Usage         :    0 bytes   0.0 % Full

    Done executing task "RunOutputFileVerifyTask".

Done building target "CoreBuild" in project "Test.cppproj".

Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').

Target "Build" in file "C:\Program Files\Atmel\Atmel Studio 6.2\Vs\Avr.common.targets" from project "C:\Users\Roy\Desktop\Test\Test.cppproj" (entry point):

Done building target "Build" in project "Test.cppproj".

Done building project "Test.cppproj".

 

Build succeeded.

========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The thing that makes me thing it's something a little deeper is :

 

No definition for the PCINTx flags.

 

It does not matter what I do, when I set any flag in the PCMSK0 register, my program stop working. 

Why does the data sheet have two values for some registers in the register summery page? One with land another without ( )?

 

Thank you for you time 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I feel very embarrassed blush

I found the problem. 

It was hardware, not software. As it turns out, there was a tiny fleck of solder that was shorting out PA5.

 

Thank you for the effort you took in looking at my problem and I'm sorry that I took up you time.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

That still doesn't make much sense.  As it is an input, shorted one way or the other shouldn't matter.  Neither should value in PCMSK0.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.