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

putc, printf, fputc, fprintf, etc Question

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



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

putc, printf, fputc, fprintf, etc Question
PostPosted: Thu Jul 26, 2012 12:39 am     Reply with quote

Hi, fellow programmers.

When using CCS-provided EUSART function to send data, does it allow multi tasking?
For example, let say i use
Code:

puts(myString);

If myString has length of 5, and baud rate is 4800, it takes 11/4800*5 = about 11ms to completely send the string. Does the program wait 11ms seconds? or does it run in back ground using #INT_TBE?
Because in real time application with program cycle of only about a few ms, we can't afford to wait that long.

Anyone idea? Thank you.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu Jul 26, 2012 1:15 am     Reply with quote

Don't know whether the built-in routines do that for you. I strongly suspect they are blocking.

That's an application where I'd implement my own circular buffering and interrupt driven transmit routine. I tend to do that anyway for any serious serial-using application.

That way you have full control, and you use sprintf and its cousins to format the data prior to buffering it.

RF Developer
Ttelmah



Joined: 11 Mar 2010
Posts: 19510

View user's profile Send private message

PostPosted: Thu Jul 26, 2012 1:16 am     Reply with quote

The standard io functions in CCS, are blocking, except for the fractionally under two characters of hardware buffering in the chip itself (for PIC16/18). So if you are using the hardware UART, and send "Fred", the call will return after the 'F', and the 'r' are sent.
So in your '5 character' example, after 6.24mSec.

Remember there is no 'OS' behind the code, so nothing to handle buffering.

To buffer the output, use EX_STISR.c, which contains an INT_TBE handler and buffer example. In CCS, printf etc., are 'expanded' over the standard functions, in allowing _you_ to specify the routine they send to, so if you include the data definitions, #int_tbe code and bputc from EX_STISR, then you can call printf, with:

printf(bputc,"The string to print");

or

printf(bputc,"%s",myString);

and the characters will be buffered (you have to enable global interrupts in your code as well).

Best Wishes
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Jul 26, 2012 7:20 am     Reply with quote

Asynchronous serial I/O by the PIC MCU is often conflated with the I/O experience encountered with a PC. A PC OS will have massive hidden buffers and will time slice (share CPU cycles) as well as use hidden hardware interrupts.
The method with a PIC that is most likely to get the results that a PC experience gives is to use circular buffers driven by the corresponding I/O interrupts and matching ISR's. A modern PIC will usually have enough RAM for these buffers. Anyone interested in success with their PIC serial I/O should first study EX_STISR.c.
CCS is good at giving built in functionality it might be a good idea to have an extension to printf say bprintf that behind the scenes creates a buffer and the isr. Or maybe it is added to the #USE something like BUFFERED=64 for a 64 byte buffer. So many PIC coders don't look at EX_STISR.c
and then have an unsuccessful experience with serial I/O.
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