ATMEGA324 External Interrupts seem to stop working

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

Hi !

A friend of mine is working on a project and I've been able to help him out for most of the stuff but we are now stuck on something and we can't quite understand why.

He's developing a small car with an ATMEGA324 controlled with a joystick in an ATMEGA88. Both microcontrollers communicate through Bluetooth with serial.

Everything basic is working fine. The issue is that he had a code for the car to park itself using some proximity sensores, that work fine. When we tested just the function for the parking by itself with was OK. When we added the serial communication to indicate when to start parking the problemas began. For some reason we don't identify, when the micros are communicating, the external interrupts (INT0,INT1,INT2) seem to stop working and so the distance read is always 0 or another constant number.

This is the initialization for the interrupts:

MCUCR |= (1<<JTD);
MCUCR |= (1<<JTD);

DDRA |= (1<<4) | (1<<7) | (1<<6);

TCCR1A = 0b00000000;
TCCR1B = 0b00000000;
TCNT1 = 0;
TIMSK1 = (1<<TOIE1);
EICRA = (1<<ISC01) | (1<<ISC00);
EIMSK = (1<<INT0);

Here's for the motors and UART:

TCCR2A = 0b10100001;
TCCR2B = 0b00000010;

DDRD |= (1<<6) | (1<<7) | (0<<2) | (0<<3);
DDRC = 0xFF;

UCSR0A = (1<<U2X0);
UCSR0B = (1<<TXEN0) | (0<<UCSZ02) | (1<<RXEN0) | (1<<RXCIE0);
UBBR0L = 25;

DDRB|=(1<<0) | (0<<2);
sei;

The microcontroller receives a string like "128|127\!/" and calls a function to process it and checks if it contains a '!' at the end which works fine.

If it does in fact contain that character it goes to this function:

The shoot function is the one that triggers the pins for the interrupt in the sensors:

And the interrupts :

The UART reception works by interrupt. I've tried disabling it and also using sei(); to make sure the external interrupts are enabled but if I do that, the UART reception interrupt doesn't stop. If I don't use sei(); the reception stops but the value of distance from sensors in the interrupts doesn't change. If I don't use sei(); and don't disable RXCIE the same thing happens.
Worth mentioning that when teste only the value of distance without the Bluetooth sending anything it works fine. As soon as the Bluetooth modules pair, the value either goes to 0 or stays at a constant number never changing.

Is there any idea that can help?

I'll have classes now but I'll try to answer as quickly as possible.

Thank you.
PS: Sorry for adding images for the functions but the "add code" functionality wasn't working for me.

Last Edited: Wed. Jan 3, 2018 - 02:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about the code for the ISRs?

Greg Muth

Portland, OR, US

Atmel Studio 7 (Version: 7.0.1652) on Windows 10

Xplained/Pro/Mini Boards mostly

 

 

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

Post a complete test program that exhibits the symptoms.  [...and the rest of the usual check list such as toolchain and version and optimization level and ...]

 

My first guess is a lack of "volatile".

 

What evidence saus "external interrupt stops working"?  Many many millions of this model series in use; surely a lot of them use external interrupts.  You would think that if they "stop working" that the situation would have been noticed before this.

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

@pesandturok:

 

A couple things:

 

  • DO NOT modify the code in your posts.  Use a reply to re-post new code.  Changing the code makes it difficult to follow.
  • DO NOT post code by using a screen capture.  Post code like you did the first time, using the <> button.  It is impossible to copy/paste code from a picture.

 

Because the problem appears after enabling the USART, it is probably in the USART code, which you did not post.  We need to see the USART initialization and ISR code.

 

Greg Muth

Portland, OR, US

Atmel Studio 7 (Version: 7.0.1652) on Windows 10

Xplained/Pro/Mini Boards mostly