usbPoll() in Timer0 interrupt routine.
Posted: Thu Feb 24, 2011 10:54 pm
Hello,
I wrote following program:
When I connect my device to my computer, the device is not recognized. There is something wrong with Timer0 interrupt routine. I do not even know if it is possible to place usbPoll() in interrupt routine. If I put usbPoll() to 'for' loop everything works fine. Could someone tell me if it is possible to call usbPoll() in any interrupt routine. If yes, please write how.
I wrote following program:
Code: Select all
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h> /* for sei() */
#include <util/delay.h> /* for _delay_ms() */
#include <avr/pgmspace.h> /* required by usbdrv.h */
#include "usbdrv/usbdrv.h"
#include "usbdrv/requests.h" /* The custom request numbers we use */
#include "usb_interface.h"
#include "lcd.h"
int main(void)
{
DDRB = 0xFF;
DDRD = 0xF0; //D+ and D- both as input;
// usb init
usbInit();
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
usbDeviceConnect();
// interrupt enable
sei();
//Timer0 init
TCCR0 = (1<<CS00);
TIMSK = (1<<TOIE0);
TCNT0 = 223;
// init other devices
lcd_init();
for(;;){}
return 0;
}
/* ------------------------------------------------------------------------- */
ISR(TIMER0_OVF_vect)
{
usbPoll();
TCNT0 = 230;
}
When I connect my device to my computer, the device is not recognized. There is something wrong with Timer0 interrupt routine. I do not even know if it is possible to place usbPoll() in interrupt routine. If I put usbPoll() to 'for' loop everything works fine. Could someone tell me if it is possible to call usbPoll() in any interrupt routine. If yes, please write how.