|
|
View previous topic :: View next topic |
Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 220
|
USB as UART and Timer Interrupt issue on 18F2550 ? |
Posted: Thu Mar 20, 2014 2:27 am |
|
|
Hello everyone,
I'm trying to use USB UART and Timer interrupt but after I active Timer interrupt, the Pic can still send data through USB UART, but it does not receive data from the PC anymore and I have to restart the PIC.
If I don't active timer interrupt, everything works well.
So my question is :
Is it possible to use USB UART and Timer interrupt at the same time ?
Thank for your help.
V5.015 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Thu Mar 20, 2014 3:17 am |
|
|
What do you mean by 'USB UART'?.
USB does not involve a UART at all....
It can _emulate_ an async serial connection if programmed as a CDC device, but is not a directly a 'UART'.
Anyway, key thing is what your timer interrupt 'does'. With USB, there are events that _must_ be handled without very noticeable delays. A few mSec at most in some cases. If your Timer interrupt handler is badly written, and does a lot, in the handler, it'll cause problems. This is the same with any interrupt handler. In general the rule is, 'keep interrupt handlers quick'. If you have a complex/long operation that needs to be triggered by an interrupt, then set a flag, and have the actual operation performed out in the main code sequence, when this flag is set. If (for instance), you perform floating point maths, or delays in an interrupt handler, then this _will_ cause problems with other handlers, particularly for things like USB.
However, the fact that you can still send data, says that the USB handling code is still running. Are you doing something like trying to talk to the USB code inside the timer interrupt?. If so, look at ex_usb_serial3.c, which shows how this has to be handled. If you call usb_cdc_getc, from inside an interrupt, when data is not available, this will deadlock the usb receive. This shows a 'workround' for this. The best way again though is to move everything from inside the timer routine, into the external code, and trigger it with a flag. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|