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

Undefined identifier fgetc

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







Undefined identifier fgetc
PostPosted: Wed Jul 05, 2006 8:39 am     Reply with quote

Guys...help...

PIC16C73B (soon to be PIC16F73)
Two serial ports...
I can send data out to each port.
I see data arriving back at the receive pins.
Can't capture this in code.

When I try to use fgetc( stream ), the compiler bombs...what am I missing?

Code:

#use rs232(baud=4800, xmit=PIN_A3, rcv=PIN_A2, STREAM=DBG)
#use rs232(baud=4800, xmit=PIN_C7, rcv=PIN_C6, STREAM=MDM)

<SNIP>

BYTE     boGotFirstModemRespChar( unsigned long ulTimeoutSecs, unsigned char ucExpectedPacketType )
{
    unsigned long   ulModemRespTimeout10Us;
    BYTE         boGotFirstChar;
    BYTE            boWaitingForPcktHdr;
    unsigned char      ucChar;
    unsigned long      ulTimeout;
   
    boWaitingForPcktHdr = true;
    boGotFirstChar = FALSE;
   
    ulTimeout = ulTimeoutSecs;
      fprintf( DBG, "Waiting for response from modem\r\n" ); [color=red]THIS WORKS FINE[/color]
      while ( boWaitingForPcktHdr == true )
      {
         
         ulModemRespTimeout10Us = 0;
         
       while( !kbhit( MDM ) && (ulModemRespTimeout10Us < 100000 ))
       {
           delay_us( 10 );
           ulModemRespTimeout10Us++;
       }
      
       if ( kbhit( MDM ) )
       {
          fprintf( DBG, "Something on the rcv buffer\r\n" );
          ucChar = fgetc( MDM );  [color=red]THIS FAILS TO COMPILE[/color]
          fprintf( DBG, "%X", ucChar );
          if( ucChar == PKT_HEADER )
          {
             if( fgetc( MDM ) == ucExpectedPacketType )
             {
                boGotFirstChar = true;
                boWaitingForPcktHdr = False;
             }

          }
       }
       
       ulTimeout--;
       
       if(ulTimeout == 0)
       {
          boGotFirstChar = FALSE;
          boWaitingForPcktHdr = false;
       }
   
     }
     fprintf( DBG, "\r\n" );
    return boGotFirstChar;
}


If I compile with fgetc( MDM ), I get Undefined Identifier fgetc


If I replace fgetc( stream ) with getc( stream ), the program compiles but I can't capture received data...probably because getc doesn't take a stream parameter?

I've tried swapping the orders of the #use directives...no joy.

Any help greatly appreciated.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Jul 05, 2006 9:31 am     Reply with quote

Replace this:
#use rs232(baud=4800, xmit=PIN_C7, rcv=PIN_C6, STREAM=MDM)
for this:
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, STREAM=MDM)

Humberto
Stumped
Guest







RE: Undefined identifier fgetc
PostPosted: Wed Jul 05, 2006 9:57 am     Reply with quote

Humberto wrote:
Replace this:
#use rs232(baud=4800, xmit=PIN_C7, rcv=PIN_C6, STREAM=MDM)
for this:
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, STREAM=MDM)

Humberto


I have pinned out the connections correctly. As I mentioned, I can see data transmitted over each serial line thru hyperterminal. When sending data back, I see activity on the correct rcv pin on the PIC.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: RE: Undefined identifier fgetc
PostPosted: Wed Jul 05, 2006 10:02 am     Reply with quote

Stumped wrote:
Humberto wrote:
Replace this:
#use rs232(baud=4800, xmit=PIN_C7, rcv=PIN_C6, STREAM=MDM)
for this:
#use rs232(baud=4800, xmit=PIN_C6, rcv=PIN_C7, STREAM=MDM)

Humberto


I have pinned out the connections correctly. As I mentioned, I can see data transmitted over each serial line thru hyperterminal. When sending data back, I see activity on the correct rcv pin on the PIC.


I think you mean you have set the use statement to match your hardware configuration however you are forcing the compiler to use software uart emulation because you have transposed the transmit and receive pins with respect to the hardware UART pin assignments.

Because you are using the software UART you must be calling kbhit(MDM) at least 10 times the bit rate. You did not mention the clock rate you are using for the PICs. Taking into account the clock rate and the delay you have inserted in the loop you may be missing characters.

I do not now why the code does not compile - there may be some reason outside the section you have listed.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!


Last edited by asmallri on Wed Jul 05, 2006 10:10 am; edited 1 time in total
Ttelmah
Guest







PostPosted: Wed Jul 05, 2006 10:05 am     Reply with quote

The point being made by Humberto, is that you are using software serial on both ports. You have the wiring wrong, to use the hardware UART, and the compiler will simply substitute a software UART for this. Unfortunately, there will be no warning that this is happening. As such, it means that only one stream will ever work at a time, there will be no hardware buffering, etc. etc.. This reduces massively, the chances of getting code to work, trying to do multiple things...

Best Wishes
Stumped
Guest







Thanks
PostPosted: Wed Jul 05, 2006 3:38 pm     Reply with quote

Ttelmah wrote:
The point being made by Humberto, is that you are using software serial on both ports. You have the wiring wrong, to use the hardware UART, and the compiler will simply substitute a software UART for this. Unfortunately, there will be no warning that this is happening. As such, it means that only one stream will ever work at a time, there will be no hardware buffering, etc. etc.. This reduces massively, the chances of getting code to work, trying to do multiple things...

Best Wishes


Thanks to all above.

As we're going through a SIPEX 233 chip, there's not much can be done except respin the pcb's.

Thanks again...stooopid mistake.

PS. Apologies Humberto if I sounded terse.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Jul 05, 2006 4:10 pm     Reply with quote

Stumped, all is ok.

We have a phrase in Spanish: "to the best hunter, the hare escapes to him".
I thought that as soon you read my advice you will realize what was going on.

Anyway IMO you not only need to "respin the pcb's" as you says but also to rewrite your code.
1) You do not need while( !kbhit( MDM )....
2) Instead you will need a short INT_RDA handler. To use ucChar = fgetc( MDM );
3) You would use fprintf( DBG, "%X", ucChar); only in main.


Humberto
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