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

fprintf and printf doesn't work

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



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

fprintf and printf doesn't work
PostPosted: Mon May 04, 2015 7:56 am     Reply with quote

Greetings! I'm using Mplab v8.91, CCS v4.134 and PIC18F86J65. When I'm using fputc() or putc() everything is fine, but when I switch to printf there is nothing on the TX pin.
Code:

#include <18F86J65.h>
#Fuses HS,NOWDT
#use delay(clock=10M)
#use rs232(baud=115200, xmit=PIN_G1, rcv=PIN_G2, bits=8, errors,PARITY=N, stream=MyStream)

void main()
{
 delay_ms(100);
 while(1)
{
    fprintf(MyStream,"text\r\n");
}
}


Where is the problem?
I need to send strings through UART and using putc is annoying, so I need a command to send the entire string at once.
Thanks!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue May 05, 2015 1:51 pm     Reply with quote

what CCS version??

and does it work with TX1/RX1 on C6,C7 ???
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Wed May 06, 2015 1:28 am     Reply with quote

Very difficult to know, since this is a old compiler. There was a period at about this point, where some major problems did appear, but I don't think with anything quite this basic. I have a 'gap' in my stored compiler versions at this point, because some features were not working correctly....

However compiling on 4.137 (the next one I have), and one just slightly earlier (4.128), gives identical code, which works correctly. Merrily thumping the bytes into TXREG2, and waiting on TX2IF to send each byte. Also correctly setting the TRIS on PortG as required. A search here finds 4.134 being used OK, in some cases on similar chips. When I say 'identical code', I mean byte identical. 4.128, .137, and a recent V5 compiler all give exactly the same output, ending with a sleep at address 0x9E for the code as posted.

It's possible it was something like a single version problem. If so, you could try adding a wrapper:
Code:

#include <18F86J65.h>
#Fuses HS,NOWDT
#use delay(clock=10M)
#use rs232(baud=115200, xmit=PIN_G1, rcv=PIN_G2, bits=8, errors,PARITY=N, BRGH1OK, stream=MyStream)

#inline
void putu2(int8 v)
{
  fputc(vMyStream);
}

void main()
{
 delay_ms(100);
 while(1)
 {
    printf(putU2,"text\r\n");
 }
}


This forces the compiler to route printf 'through' the fputc routine, rather than generating embedded code for this.
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