|
|
View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
fprintf and printf doesn't work |
Posted: Mon May 04, 2015 7:56 am |
|
|
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
|
|
Posted: Tue May 05, 2015 1:51 pm |
|
|
what CCS version??
and does it work with TX1/RX1 on C6,C7 ??? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed May 06, 2015 1:28 am |
|
|
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. |
|
|
|
|
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
|