usbPoll() in Timer0 interrupt routine.

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
maciek_nh
Posts: 1
Joined: Thu Feb 24, 2011 10:45 pm

usbPoll() in Timer0 interrupt routine.

Post by maciek_nh » Thu Feb 24, 2011 10:54 pm

Hello,

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.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: usbPoll() in Timer0 interrupt routine.

Post by maxi » Fri Feb 25, 2011 3:57 am

You should be calling usbPoll() from the main loop. It is a bad idea in any case to call a subroutine from an ISR
6.- Interrupts and Timing - Make sure that you're not using interrupts higher than the interrupt you have set for VUSB. Also make sure you're not disabling interrupts for longer than a few milliseconds, or that you have more than 10ms between calls to usbPoll(). A common mistake is to have sections of floating-point calculations in a main loop which does call usbPoll(), however, keep in mind that floating-point math is EXTREMELY slow, it may be worthwhile to place usbPoll() before and after these calculations.

Augend
Posts: 3
Joined: Sat Feb 26, 2011 9:32 am

Re: usbPoll() in Timer0 interrupt routine.

Post by Augend » Sat Feb 26, 2011 9:41 am

If you put big codes in main loop your device will not be seen in next system enumeration. calling usbpoll() in short intervals is mandatory for device recognition. if you are using a watchdog dont forget to reset it during your calculations.

Post Reply