Example code for USB_COM_vect

AdamG

New member
I have hunted around but haven't been able to find example code or documentation for using the USB interrupt USB_COM_vect. I am specifically wanting to get an interrupt on the 4.1 when there is data available to be read rather than polling for data.
Any help much appreciated.

Adam
 
I have hunted around but haven't been able to find example code or documentation for using the USB interrupt USB_COM_vect. I am specifically wanting to get an interrupt on the 4.1 when there is data available to be read rather than polling for data.
Any help much appreciated.

Adam

Hi Adam, when you say "polling for data", do you mean using Serial.available() and Serial.read() to get data sent via USB Serial?
 
Yes, that is exactly what I am doing currently.. Thanks.

Can you say more about what you're trying to do, and why you think you need to go to the lower levels and hook into the ISR? For all Serial comm, whether it's USB serial or UART (hardware) serial, the available/read/write functions are the "right" way to access those devices.

If you do want to go deeper on USB Serial, look at files usb_serial.c and usb.c in cores\Teensy4. You'll see that usb_serial.c has a function named rx_event(), which gets called by the USB isr. That function is "registered" via the function usb_config_rx() in file usb.c, which is also where you'll find the actual ISR function usb_isr().
 
The vast majority of the time the device is processing data and sending it to the host computer, data in the other direction is far less frequent and I was interested in implementing dealing with it as needed via interrupt rather than checking during the flow of normal running of its tasks.

I'll dig around the files you mentioned above. Thanks.
 
The vast majority of the time the device is processing data and sending it to the host computer, data in the other direction is far less frequent and I was interested in implementing dealing with it as needed via interrupt rather than checking during the flow of normal running of its tasks.

One last comment, there is an event mechanism whereby your program can be "notified" that Serial.available() is true, but keep in mind this is done by polling behind the scenes, so it's probably more efficient for you to call Serial.available() at whatever you think is the appropriate frequency. See files EventResponder and Yield in cores\Teensy4. There must be forum threads about them, too.
 
Back
Top