Hello to all! My name is Luca and this is my first post on AVR Freaks!
I have a problem with my attiny4313. My objective is to acquire a signal with a certain frequency and send this value to my pc. For do this, i have programmed the follows periphericals of my attiny:
- External interrupt INT0: I use this to count the pulse signal of the sensor.
Timer Counter 0 in CTC mode: I use this to take with certain frequency the count pulse value.
Usart: To sent the count pulse value to my pc.
This is my code:
#include#include void initIO(void); void initUSART(void); void initExtInterrupt(void); void initTimerCounter0(void); int main(void) { initIO(); initUSART(); initExtInterrupt(); initTimerCounter0(); sei(); while(1){ // turning the thumbs.. } } void initIO(void){ DDRD &= ~(1<<2); // pin D.2 (INT0) it's input PORTD |=(1<<2); // pull-up on D.2 DDRB |=(1<<0) |(1<<1); } void initExtInterrupt(void){ GIMSK |= (1<<INT0);// enable INT0 MCUCR |= (1<<ISC01) | (1<<ISC00) ; // interrupt on rising edge of input signals } void initTimerCounter0(void){ TIMSK |= (1<<OCIE0A);// enable timer-counter0 interrupt TCNT0 = 0; OCR0A = 194;// 20.03 Hz @ 8/1024 MHz TCCR0A |= (1<<WGM01);// timer-counter0 in CTC mode TCCR0B |= (1<<CS02) | (1<<CS00);// start timer-counter0 @ FCPU/1024 } void initUSART(void){ UCSRB |= (1<<RXCIE) | (1<<UDRIE) | (1<<RXEN) | (1<<TXEN); //enable tx, rx and their interrupts UCSRC |= (1<<UCSZ1) | (1<<UCSZ0);// USART setting UBRRL = 51;//baud rate @ 9.6K ^ @8Mhz } ISR(INT0_vect){// update impulse counter PORTB ^= (1<<0); } ISR(TIMER0_COMPA_vect){// take the value PORTB ^= (1<<1); } ISR(USART_UDRE_vect){// Tx a byte ... } ISR(USART_RX_vect){// Rx a byte ... }
This code doesn't work. I used the leds of the my stk500 to verify the program. In this case the led of the impulse counter routine (led 0) blinks, while the led of the timer counter doesn't blinks.
Instead, if I comment the line of code where I go to initialize the device USART:
initIO(); //initUSART(); initExtInterrupt(); initTimerCounter0();
then both leds blink.
I tested separately each part of the code, and they alone working. but when put together the various pieces of code, they do not work.
There are some problem of compatibility with these device? How i can resolve this problem?
Thank to all.