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

Using fputc causes printf to stop working.

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



Joined: 30 Sep 2003
Posts: 89

View user's profile Send private message

Using fputc causes printf to stop working.
PostPosted: Wed Aug 19, 2009 10:41 am     Reply with quote

This is the shortest code I could write to fully demonstrate the problem.

I use fputc() to send data out the second serial port and use printf() to send information to a diagnostics display to the first serial port.

What I find is that I can use printf() ONCE after my first fputc(), then it won't put anything out anymore.

I have an option to write directly to the transmit register of the second serial port, but I want to take advantage of the parity control that fputc() gets me.

Note that I have a:
#define USE_FPUTC
that you can use to swap between using fputc() and the direct method.

Thanks,

-Pete



Compiler version PCWH 3.249

Code:

#include <18F8622.h>
#use delay(clock=10000000)
#fuses HS, NOWDT, PUT, BROWNOUT, NOLVP

#fuses NOPROTECT, NOWRT, NOEBTR //needed only for my board

#use rs232(baud=312500, xmit=PIN_G1, rcv=PIN_G2, ERRORS, parity=O, bits=8, stream=SERIAL2)

#use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7, ERRORS, parity=N, bits=8)

char txreg2;
#LOCATE txreg2 = 0xf6d
char rcsta2;
#LOCATE rcsta2 = 0xf6b
char txsta2;
#LOCATE txsta2 = 0xf6c



#use standard_io(F)  //used pin_F6 for analyzer signal



#define  USE_PRINTF  //remark out to disable printfs
#ifdef USE_PRINTF 
   #define USE_PRINTF(x) x
#else
   #define USE_PRINTF(x)
#endif

//======================================
void main(void)
{
output_low(PIN_F6);
delay_ms(100);


output_high(PIN_F6);
USE_PRINTF(printf("\n\rSTART\n\r");)
output_LOW(PIN_F6);

#define USE_FPUTC  //remark out to write directly to the 2nd serial port

#ifdef USE_FPUTC

   USE_PRINTF(printf("A\n\r");)
   fputc(0x01, SERIAL2);
   delay_us(30);

   USE_PRINTF(printf("B\n\r");)
   fputc(0x05, SERIAL2);
   delay_us(30);

   USE_PRINTF(printf("C\n\r");)
   fputc(0x15, SERIAL2);
   delay_us(30);

   USE_PRINTF(printf("D\n\r");)
   fputc(0x55, SERIAL2);

#else
   USE_PRINTF(printf("E\n\r");)
   while( !bit_test(txsta2,1))
      {}
   txreg2=0x01; //1 bit
   delay_us(30);

   USE_PRINTF(printf("F\n\r");)
   while( !bit_test(txsta2,1))
      {}
   txreg2=0x05; //2 bits
   delay_us(30);

   USE_PRINTF(printf("G\n\r");)
   while( !bit_test(txsta2,1))
      {}
   txreg2=0x15; //3 bits
   delay_us(30);

   USE_PRINTF(printf("H\n\r");)
   while( !bit_test(txsta2,1))
      {}
   txreg2=0x55; //4 bits

#endif

   while(1){}

}

_________________
-Pete
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 19, 2009 12:54 pm     Reply with quote

You should be using fprintf with streams, not printf.
Also, you should assign a stream ID to the #use rs232() statement for
pins C6 and C7. Use fputc and fprintf with it also, with the stream ID.
pfournier



Joined: 30 Sep 2003
Posts: 89

View user's profile Send private message

PostPosted: Wed Aug 19, 2009 1:03 pm     Reply with quote

So, if I understand you right, if I use streams for one UART, I am forced to use streams when accessing the other UART?
_________________
-Pete
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Wed Aug 19, 2009 6:14 pm     Reply with quote

Whenever using RS232 on a PIC with TWO EUSART channels - always assign a stream id to EACH ( both) uarts.

At the least it is insurance against future compiler revisions breaking
what you wrote.
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