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

RS232_ERRORS for multiple hardware uarts

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



Joined: 29 Jun 2007
Posts: 62
Location: Raleigh, NC

View user's profile Send private message Visit poster's website

RS232_ERRORS for multiple hardware uarts
PostPosted: Sun Sep 07, 2008 9:32 am     Reply with quote

I'm using both hardware uarts on an 18F6722 for 2 separate high-speed serial streams. My application requires detection of framing errors for each port individually.

Is there a separate RS232_ERRORS variable for each uart, or do I need to write my own code to directly access RCSTA1 and RCSTA2 separately?

Thanks for your help,
Jim
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Sep 07, 2008 2:21 pm     Reply with quote

For questions like this the easiest thing to do is to write a small test program.
Code:
.................... #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=UART1)
....................   fgetc(UART1);
00004:  BTFSS  PIR1.RC1IF
00006:  BRA    0004
00008:  MOVFF  RCSTA1,rs232_errors
0000C:  MOVFF  RCREG1,01
00010:  BTFSS  rs232_errors.1
00012:  BRA    0018
00014:  BCF    RCSTA1.CREN
00016:  BSF    RCSTA1.CREN
00018:  GOTO   0070 (RETURN)
.................... #use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2, ERRORS, stream=UART2)
....................   fgetc(UART2);
0001C:  BTFSS  PIR3.RC2IF
0001E:  BRA    001C
00020:  MOVFF  RCSTA2,rs232_errors
00024:  MOVFF  RCREG2,01
00028:  BTFSS  rs232_errors.1
0002A:  BRA    0030
0002C:  BCF    RCSTA2.CREN
0002E:  BSF    RCSTA2.CREN
00030:  GOTO   0072 (RETURN)

What you see is that both UART1 and UART2 write the status data to the same rs232_errors variable. This implies that the status in rs232_errors will be overwritten as soon as getc is called for either of the two serial ports.
soundscu



Joined: 29 Jun 2007
Posts: 62
Location: Raleigh, NC

View user's profile Send private message Visit poster's website

PostPosted: Sun Sep 07, 2008 3:33 pm     Reply with quote

Agreed, and thank you for the examples.

After finding that RS232_ERRORS does not produce the desired results when both ports are receiving simultaneously, I used #BYTE to declare RCSTA1 and RCSTA2 at their hardware addresses, then tested them instead of RS232_ERRORS for the framing error flag.

This works perfectly.

Jim
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