Myself and a friend have been engaged in a personal project where we are utilising a ATmega32a to eventually control 12 hobby servo motors in four legs, each with three joints. The ATmega32a is installed on a board a friend of mine designed called a Penguino, which quite nicely fits on a prototyping bread board. To this end the hardware UART is occupied with the computer interface and so we have to write our own software based UART to communicate through the DIO pins.
We thought it would be fun to write our own UART rather than use a supplied one but allas we have gotten quite stuck. I was wondering if you could help us. Bellow is a simplified version of our code which (also) does not work. The version bellow just uses the ISR to output a changing signal. When we measure the signal sent through the pin with an oscilloscope all we get is a signal high.
#include <avr/io.h>
#include <avr/interrupt.h>
#define OUTPUT_PIN (1<<7)
void initGeneral(void)
{
// Set Port A pin as output
DDRA |= OUTPUT_PIN;
// Set Port A pin output to 0
PORTA &= ~OUTPUT_PIN;
}
void initInterruptTimer0Comp(void)
{
// Set the value to count to for the timer
OCR0 = 25;
// Set prescalar to 64, and clear timer on compare
TCCR0 = ((1<<CS00)|(1<<CS01)|(0<<CS02)) | (0<<WGM00)|(1<<WGM01);
// Clear pending interrupts
TIFR |= 1<<OCF0;
// Set enable Output Compare Interrupt for Timer 0
TIMSK |= 1<<OCIE0;
// Enable all interrupts (AVR gcc specific)
sei();
}
ISR(TIMER0_COMP_vect)
{
staticint sendBit = 7;
char sendByte = 0xAA;
if (sendBit < 0);
{
sendBit = 7;
}
char signal = sendByte & (1 << sendBit);
if(signal == 0)
{
PORTA &= ~OUTPUT_PIN;
}
else
{
PORTA |= OUTPUT_PIN;
}
sendBit--;
}
int main(void)
{
initGeneral();
initInterruptTimer0Comp();
while(1);
return 0;
}
However we know that there is nothing wrong with the interrupt calling the ISR because if we replace the ISR with the code bellow we get an alternating signal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ISR(TIMER0_COMP_vect)
{
staticint x=0;
if (x == 0)
{
x=1;
PORTA &= ~OUTPUT_PIN;
}
else
{
x=0;
PORTA |= OUTPUT_PIN;
}
}
Do you guys have any thoughts?
Thanks a heap for your time. My name is David and my collaborators name is Davids. So, thanks form Dave and Dave