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

#use rs232 syntax for ccs

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



Joined: 15 Jan 2015
Posts: 2
Location: 051 Village Dr., Buena Park, CA

View user's profile Send private message

#use rs232 syntax for ccs
PostPosted: Thu Jan 15, 2015 9:40 am     Reply with quote

I have a project which has few files. One of the files has a syntax #use rs232 to initialize the usart1. Given below.

Code:
#use rs232(uart1, baud=19200, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)
#int_RDA
void  RDA1_isr(void)
{
   UCHAR receive_byte;
......................
......................
}

I have another #use syntax in another file which initialize the usart2.
Code:
#use rs232(uart2, baud=19200, parity=N, xmit=PIN_G1, rcv=PIN_G2, bits=8)
#int_RDA2
void RDA2_isr(void)
{
   // Transfer the received byte from the UART to the DACT receive buffer
   DACT_receive_buffer[DACT_receive_buffer_load_index] = RCREG2;
.............................
.............................
}

when I compile the project I get this error message

--- Info 300 "C:\My_Test_HCA\HCA\Code\FS1K_intrpt.c" Line 448(5,8): More info: First Declaration of STDIN
*** Error 31 "C:\My_Test_HCA\HCA\Code\pic_RemPanel.c" Line 730(5,74): Identifier is already used in this scope
1 Errors, 1 Warnings.
Build Failed.

If I remove any one of the #use rs232(.............. ) syntax, it compiles well. Appreciate your help. I am new to this compiler.
_________________
Kumar
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 15, 2015 12:46 pm     Reply with quote

The last #use rs232() line in the file controls the configuration for all
putc, getc, printf, etc., that occur after that line.

When using multiple #use rs232() statements, you should add the Stream
parameter to each statement. Give each #use rs232() statement a
unique Stream name, such as COM1, COM2, GPS1, TERM1, or whatever
you want. Then use fputc, fgetc, fprintf, etc. to specify the stream name
for each function. See the CCS manual.
Kumar Sin



Joined: 15 Jan 2015
Posts: 2
Location: 051 Village Dr., Buena Park, CA

View user's profile Send private message

PostPosted: Thu Jan 15, 2015 1:12 pm     Reply with quote

I am not using putc, getc. instead I use RCREG1 and RCREG2 registers defined in PIC18F86J11_ccs.h file to received the data from usart1 and usart2.

Code:
#use rs232(uart1, baud=19200, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8)
#int_RDA
void  RDA1_isr(void)
{
   UCHAR receive_byte;

   // Read the received byte from the UART??
   receive_byte = RCREG1;
.............

}

#use rs232(uart2, baud=19200, parity=N, xmit=PIN_G1, rcv=PIN_G2, bits=8)
#int_RDA2
void RDA2_isr(void)
{
   // Transfer the received byte from the UART to the DACT receive buffer
   DACT_receive_buffer[DACT_receive_buffer_load_index] = RCREG2;

........
}

This code worked previously, may be older version of the compiler. The previous programmer wrote this code and worked. Without modifying it, I used 45 days trial version of the compiler to compile this code. I get this error message. May be old version of the compiler tolerate this???
_________________
Kumar
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 15, 2015 1:45 pm     Reply with quote

I can't test it without knowing the old compiler version.

If you use streams with vs. 5.036, then it will compile with no errors.
Ttelmah



Joined: 11 Mar 2010
Posts: 19375

View user's profile Send private message

PostPosted: Thu Jan 15, 2015 2:49 pm     Reply with quote

Still just add the stream identifier. This doesn't stop the hardware registers being used, and will allow the two initialisations.
As a comment, _either_ use 'uartx', _or_ use the pin numbers. Not both.

As a further comment, why not use getc?.

Your code as written, is dangerous. Since you don't have 'ERRORS' in the RS232 declaration (and are not using getc), if a UART error occurs, the UART _will_ become hung. The rule of thumb is that you _must_ either have 'ERRORS', or handle UART errors yourself. If you want to do register accesses 'fair enough', but if you are doing these, then your code needs to add error handling. You need something like:
Code:

#INT_RDA
void RDA1_ISR(void)
{
   UCHAR receive_byte;

   // Read the received byte from the UART??
   receive_byte = RCREG1;
   if (OERR)
   {
      CREN=FALSE;
      CREN=TRUE;
   }
   //other code.
}

As an absolute minimum. With suitable defines for OERR, CREN etc.. You also depending on the UART, may need to handle FERR as well.
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