View previous topic :: View next topic |
Author |
Message |
nangsuep
Joined: 17 Oct 2018 Posts: 5
|
"Function used but not defined" for UART on PIC16F |
Posted: Wed Oct 17, 2018 5:25 am |
|
|
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
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Wed Oct 17, 2018 8:32 am |
|
|
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
|
|
Posted: Wed Oct 17, 2018 9:05 am |
|
|
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
|
|
Posted: Wed Oct 17, 2018 9:08 am |
|
|
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
|
|
Posted: Wed Oct 17, 2018 9:14 am |
|
|
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
|
|
Posted: Wed Oct 17, 2018 9:31 am |
|
|
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
|
|
Posted: Wed Oct 17, 2018 9:53 am |
|
|
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
|
|
Posted: Wed Oct 17, 2018 10:11 am |
|
|
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: 19537
|
|
Posted: Wed Oct 17, 2018 10:49 am |
|
|
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
|
|
Posted: Wed Oct 17, 2018 10:50 am |
|
|
Dear Sir,
It works now, beautifully.
Thank you very much for your precious time.
Kind Regards,
Phaderm |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1353
|
|
Posted: Wed Oct 17, 2018 7:31 pm |
|
|
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). |
|
|
|