CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

USB as UART and Timer Interrupt issue on 18F2550 ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
spilz



Joined: 30 Jan 2012
Posts: 220

View user's profile Send private message

USB as UART and Timer Interrupt issue on 18F2550 ?
PostPosted: Thu Mar 20, 2014 2:27 am     Reply with quote

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: 19552

View user's profile Send private message

PostPosted: Thu Mar 20, 2014 3:17 am     Reply with quote

What do you mean by 'USB UART'?.
USB does not involve a UART at all.... Smile

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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