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 support@ccsinfo.com

printf delays in transmiting buffer

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



Joined: 05 Feb 2004
Posts: 2
Location: Colorado Springs, CO

View user's profile Send private message Visit poster's website

printf delays in transmiting buffer
PostPosted: Thu Feb 05, 2004 11:33 pm     Reply with quote

Question
Can anyone tell me what the delay that the compiler uses for when the hardware RS232 buffer is full during transmitting.
I believe that the delay is longer than 15 milliseconds at 9600 baud.
The project uses a 20Mhz clock.

I am working on a project where a delay in the transmitting can cause probelms. I need to have the bytes transmit as fast as possible.

Should I be using putc instead of printf?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 06, 2004 12:03 am     Reply with quote

It doesn't do any delay. You do have to wait until a character
has been transmitted from the hardware UART, which frees up
the TXREG so it can accept the next character. The wait time
required will be:

Code:
# of bits/char          10
--------------     =  -------  = 1.04 ms
baud rate              9600

Code:
0000                00302 .................... printf("ABCDEFG"); 
0020 01A1       00303 CLRF   21
0021 0821       00304 MOVF   21,W
0022 2004       00305 CALL   004    // Fetch char from const string
0023 0AA1       00306 INCF   21,F   // Increment the char count
0024 00F7       00307 MOVWF  77     
0025 0877       00308 MOVF   77,W
0026 1E0C       00309 BTFSS  0C.4    // Is the transmitter ready ?
0027 2826       00310 GOTO   026     // If not, wait in a tight loop
0028 0099       00311 MOVWF  19      // Then send the char
0029 3007       00312 MOVLW  07      // Get the string length
002A 0221       00313 SUBWF  21,W    // Compare it to # of chars sent
002B 1D03       00314 BTFSS  03.2    // Jump if we're done
002C 2821       00315 GOTO   021  // If not done, jump to top of loop

// This code fetches a char from the const string.
0004  100A  @const  bcf    0xA,0x0                       
0005  108A          bcf    0xA,0x1                       
0006  110A          bcf    0xA,0x2                       
0007  0782          addwf  0x2                           
0008  3441          retlw  0x41      // 'A'                 
0009  3442          retlw  0x42      // 'B'                   
000A  3443          retlw  0x43      // 'C'                   
000B  3444          retlw  0x44      // 'D'                   
000C  3445          retlw  0x45      // 'E'                   
000D  3446          retlw  0x46      // 'F'                   
000E  3447          retlw  0x47      // 'G'                   
000F  3400          retlw  0x0                           

samg



Joined: 05 Feb 2004
Posts: 2
Location: Colorado Springs, CO

View user's profile Send private message Visit poster's website

I found my Bug, Thanks
PostPosted: Fri Feb 06, 2004 12:53 am     Reply with quote

Using the C/ASM code like you showed, I found that it was a goof up in the printf I was using.

printf ("\x0F\x34\x00\xF0\x04");

I needed to push out some binary values and was looking for a quick way to push out binary sequences without taking up RAM.

The ASM code will show that the string length is 2 bytes.
The NULL in the center ends the string. (NULLs can't be printed in printf! Duh!)

changed to:

int CONST sequence_1 [5] = {0x0F,0x34,0x00,0xF0,0x04};
for (i=0;i<5;i++) {
putc(sequence_1[i]);
}

I need to do this because I have a bunch of sequences and
don't want to use up RAM storing them. And I know that
const byte arrays cannot pointed to so a generic function is out.
The above seems the most efficient.
Thanks for the help!
Ttelmah
Guest







Re: I found my Bug, Thanks
PostPosted: Fri Feb 06, 2004 11:43 am     Reply with quote

samg wrote:
Using the C/ASM code like you showed, I found that it was a goof up in the printf I was using.

printf ("\x0F\x34\x00\xF0\x04");

I needed to push out some binary values and was looking for a quick way to push out binary sequences without taking up RAM.

The ASM code will show that the string length is 2 bytes.
The NULL in the center ends the string. (NULLs can't be printed in printf! Duh!)

changed to:

int CONST sequence_1 [5] = {0x0F,0x34,0x00,0xF0,0x04};
for (i=0;i<5;i++) {
putc(sequence_1[i]);
}

I need to do this because I have a bunch of sequences and
don't want to use up RAM storing them. And I know that
const byte arrays cannot pointed to so a generic function is out.
The above seems the most efficient.
Thanks for the help!

Worth pointing out that CCS, has a 'shortcut', that may allow you to use a suitable 'generic' function. Any 'putc' type function, that accepts a single integer, can be called using the syntax:

putc("Constant string");

and the function will be called once for each character in the 'Constant string'. This works with your own functions, as well as CCS ones.

Best Wishes
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