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.
PS: Sorry for adding images for the functions but the "add code" functionality wasn't working for me.