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

"Function used but not defined" for UART on PIC16F

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



Joined: 17 Oct 2018
Posts: 5

View user's profile Send private message

"Function used but not defined" for UART on PIC16F
PostPosted: Wed Oct 17, 2018 5:25 am     Reply with quote

Dear,
I got a compile-time error of "Function used but not defined" for the function rcv_buffer_bytes() and other UART-related functions. I'm using PIC16F15324 device. My main.h and main.c files are minimal as shown below.

main.h
--------
Code:
#include <16F15324.h>
#device ADC=10
#use delay(internal=16MHz)
#use rs232(baud=4800,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8,stream=PORT1)



main.c
--------
Code:
#include <main.h>
void main() {
   rcv_buffer_bytes(PORT1);
}



Any help would be appreciated,
Phaderm
Code:
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 8:32 am     Reply with quote

The error message means that your program is trying to execute the function ' rcv_buffer_bytes() ' however you've never coded that function.

I have to assume you're copying code from someone else's program and they may have a #include <my_serial_functions> file where they have several functions related to accessing the serial port of a PIC.

Jay
nangsuep



Joined: 17 Oct 2018
Posts: 5

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 9:05 am     Reply with quote

Dear,
Thanks for your comments.

I'm expecting the function "rcv_buffer_bytes()" to work because it's in the ccs_c_manual (on page 93). It's also prototyped in 16F15324.h as



Code:
// #use rs232() Prototypes:
_bif void putchar(char cdata);
_bif void putchar(char cdata, unsigned int8 stream);
_bif void puts(char* string);
_bif void puts(char* string, unsigned int8 stream);
_bif char getch(void);
_bif char getch(unsigned int8 stream);
_bif void gets(char* string);
_bif void gets(char* string, unsigned int8 stream);
_bif int1 kbhit(void);
_bif int1 kbhit(unsigned int8 stream);
_bif void printf(char* string, ...);
_bif void fprintf(unsigned int8 stream, char* string, ...);
_bif void putc_send(void);
_bif void fputc_send(unsigned int8 stream);
_bif int1 rcv_buffer_full(void);
_bif int1 rcv_buffer_full(unsigned int8 stream);
_bif unsigned int16 rcv_buffer_bytes(void);
_bif unsigned int16 rcv_buffer_bytes(unsigned int8 stream);
_bif int1 tx_buffer_full(void);
_bif int1 tx_buffer_full(unsigned int8 stream);
_bif unsigned int16 tx_buffer_bytes(void);
_bif unsigned int16 tx_buffer_bytes(unsigned int8 stream);



The strange thing is that I can use many functions in this list without error, such as getc(), getch(), getchar(), fgetc(), kbhit(), gets(), fgets(), putc(), putchar(), puts() and fputs().

Functions that will not compile are

Code:
   //The following lines cause "Function is used but not defined"
   setup_uart(9600, PORT1, 16000000);   
   rcv_buffer_bytes();
   tx_buffer_bytes();
   tx_buffer_full();
   fputc_send() ;
   putc_send();

 
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 9:08 am     Reply with quote

If you look in the CCS manual in the rcv_buffer_bytes() section, you
will see an example. It shows what you have to put in the #use rs232()
statement to allow you use rcv_buffer_bytes(). Read the manual.
nangsuep



Joined: 17 Oct 2018
Posts: 5

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 9:14 am     Reply with quote

Dear,
I have included the statement

Code:
#use rs232(baud=4800,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8,stream=PORT1)



in my main.h file.

Any further suggestions is greatly appreciated.
Phaderm
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 9:31 am     Reply with quote

If you look in the manual like I said, you will see the parameter shown
in bold, in the example below:
Quote:
#USE_RS232(UART1,BAUD=9600,RECEIVE_BUFFER=100)
void main(void) {
char c;
if(rcv_buffer_bytes() > 10)
c = getc();
}
nangsuep



Joined: 17 Oct 2018
Posts: 5

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 9:53 am     Reply with quote

Dear,
Thank you for being patient with my ignorant.
I tried to compile your given code :

Code:
#include <16F15324.h>
#device ADC=10
#use delay(internal=16MHz)

#use RS232(UART1,BAUD=9600,RECEIVE_BUFFER=100)  //causes "USE parameter value is out of range U1RX not assigned, use #PIN_SELECT"

void main(void) {
   char c;
   if(rcv_buffer_bytes() > 10) c = getc();
}


The compiler report 2 errors:

Quote:
*** Error 100 "main.c" Line 5(5,130): USE parameter value is out of range U1RX not assigned, use #PIN_SELECT

*** Error 51 "main.c" Line 9(24,25): A numeric expression must appear here


Kind Regards,
Phaderm
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 10:11 am     Reply with quote

Add the two lines shown in bold below:
Quote:
#include <16F15324.h>
#device ADC=10
#use delay(internal=16MHz)

#PIN_SELECT U1TX=PIN_C4
#PIN_SELECT U1RX=PIN_C5


#use RS232(UART1,BAUD=9600,RECEIVE_BUFFER=100) //causes "USE parameter value is out of range U1RX not assigned, use #PIN_SELECT"

void main(void) {
char c;
if(rcv_buffer_bytes() > 10) c = getc();
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 10:49 am     Reply with quote

and the key point to understand is that on chips where peripherals offer PPS (programmable pin select), the pins _must_ be setup, before you use the peripheral. Talking directly to the pins, just sets up a software UART (which doesn't implement receive buffering). So you have to select the pins to use and then use the hardware.
The receive_buffer_bytes function, only exists when you have a receive buffer implemented. Until then it doesn't exist....
nangsuep



Joined: 17 Oct 2018
Posts: 5

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 10:50 am     Reply with quote

Dear Sir,
It works now, beautifully.

Thank you very much for your precious time.
Kind Regards,
Phaderm
jeremiah



Joined: 20 Jul 2010
Posts: 1315

View user's profile Send private message

PostPosted: Wed Oct 17, 2018 7:31 pm     Reply with quote

It's worth noting that the CCS supplied rx and tx buffers have one design quirk. If you fail to service the buffers before they fill up, they completely reset, losing the internal pointers to your current data (effectively starting over).
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