|
|
View previous topic :: View next topic |
Author |
Message |
RKnapp
Joined: 23 Feb 2004 Posts: 51
|
kbhit() and RS232_ERRORS |
Posted: Fri Mar 12, 2004 9:56 pm |
|
|
Friends,
I'm using CCS v3.187 (as of today...!... god knows what it does, or why the documentation is frozen at some earlier state) and PIC18F8720 with both native UARTS. I have named my streams thus:
#use rs232(baud=115200,xmit=PIN_C6,rcv=PIN_C7,bits=8,parity=n,errors, \
stream=COM1)
#use rs232(baud=115200,xmit=PIN_G1,rcv=PIN_G2,bits=8,parity=n,errors, \
stream=COM2)
#use rs232(DEBUGGER,stream=DEBUG)
My questions are: (I admit I'm a dummy; I can't read assembly well enough to know these answers -- pls help!)
1) Can kbhit() accept an argument relating to that stream? E.g., kbhit(COM1) ?
2) Can RS232_ERRORS also somehow relate to the port in question? (Right now, in my ISRs, I analyze RS232_ERRORS like this:)
// For Rx only, RS232_ERRORS contains a near-copy of RCSTAx's err bits:
if ( RS232_ERRORS & 0x01 ) // compiler sets this
x_ErrCodes.ISR_COM1.ParityErrors++; // bit0: not "9th bit"
if ( RS232_ERRORS & 0x02 )
x_ErrCodes.ISR_COM1.OverrunErrors++; // bit 1
if ( RS232_ERRORS & 0x04 )
x_ErrCodes.ISR_COM1.FramingErrors++; // bit 2
If not, should I somehow #byte each status byte separately?
Thanks for your wisdom,
Robert |
|
|
ritchie
Joined: 13 Sep 2003 Posts: 87
|
Re: kbhit() and RS232_ERRORS |
Posted: Fri Mar 12, 2004 10:07 pm |
|
|
Quote: |
1) Can kbhit() accept an argument relating to that stream? E.g., kbhit(COM1) ? |
Yes, you can use kbhit(stream)....
Quote: |
2) Can RS232_ERRORS also somehow relate to the port in question? |
You can relate errors to a software RS232 port in question....
Quote: |
(Right now, in my ISRs, I analyze RS232_ERRORS like this:)
// For Rx only, RS232_ERRORS contains a near-copy of RCSTAx's err bits:
if ( RS232_ERRORS & 0x01 ) // compiler sets this
x_ErrCodes.ISR_COM1.ParityErrors++; // bit0: not "9th bit"
if ( RS232_ERRORS & 0x02 )
x_ErrCodes.ISR_COM1.OverrunErrors++; // bit 1
if ( RS232_ERRORS & 0x04 )
x_ErrCodes.ISR_COM1.FramingErrors++; // bit 2
If not, should I somehow #byte each status byte separately?
Thanks for your wisdom,
Robert |
This how I deal my ISR for #int_rda with error handling...
Code: |
#int_rda
void RS485_RXisr() // RS485 reception interrupt routine
{
char dump; // character dummy varaible
if (glRS485RXready) // check if ready to accept incoming data?
{
// get incoming byte from RCREG
*(RXbuffer + RXin) = RCREG;
// calculate checksum on the fly
rxchksm ^= *(RXbuffer + RXin);
RXin++; // increment data IN index
if (OERR){ // check for framing & overrun error
CREN = 0; // disables receiver
CREN = 1; // enables receiver
}
if (RXin >= RX_SIZE) // is RXin larger than RX_SIZE (64)?
RXin -= RX_SIZE; // if so? set RXin to zero
set_timer3(53536); // timer3 overflows at ~6.0mSec.
TMR3IF = 0; // reset timer3 interrupt flag
// enable timer3 interrupt
enable_interrupts(int_timer3);
}
else { // prevent buffer overflow
dump = RCREG; // get byte and store to a dummy variable
if (OERR){ // check for framing & overrun error
CREN = 0; // disables receiver
CREN = 1; // enables receiver
}
}
}
|
Hope this helps. |
|
|
Ttelmah Guest
|
|
Posted: Sat Mar 13, 2004 3:09 am |
|
|
Try looking at the 'readme' that comes with the compiler...
This details most of the major canges since the documentation.
Why CCS, do not structure their documentation, more like the old Unix 'man' pages, so that when changes are made to a command, these can immediately be reflected in the 'online' .pdf file, I do not know. Given that the programmers must (should!), be documenting changes made, this has allways been a 'bugbear' with the compiler...
Best Wishes |
|
|
RKnapp
Joined: 23 Feb 2004 Posts: 51
|
|
Posted: Sat Mar 13, 2004 8:32 pm |
|
|
Thanks, both of you!
- Ritchie, would you please show the definitions of macros / registers glRS485RXready and OERR? They're both of interest as I want to see if you've associated them with named streams.
- Ttelmah, thank you for pointing out the readme.txt file. I can see some useful stuff in there. I have to say, however, if a new version of the compiler gets released, why not release the associated help files at the same time? Tech writers are way underpaid and dirt cheap.
My heartfelt thanks to all who read these forums and help others,
Robert |
|
|
ritchie
Joined: 13 Sep 2003 Posts: 87
|
|
Posted: Sun Mar 14, 2004 5:54 pm |
|
|
RKnapp wrote: | Thanks, both of you!
- Ritchie, would you please show the definitions of macros / registers glRS485RXready and OERR? They're both of interest as I want to see if you've associated them with named streams.
Robert |
the glRS485RXready is a flag not a register!!! for my hardware UART I never use #use rs232 built-in function coz for PIC18F1320 won't support a baud rate of 115.2kbps at 8MHz... with this I decided to code to handle UART reception and transmission...
My register definition: (This is for PIC18F1320)
Code: |
#byte SPBRGH = 0xFB0 // USART baud rate generator high byte
#byte SPBRG = 0xFAF // USART baud rate generator low byte
#byte TXREG = 0xFAD // USART transmit register
#byte TXSTA = 0xFAC // USART transmit status and control register
#byte RCSTA = 0xFAB // USART receive status and control register
#byte RCREG = 0xFAE // USART receive register
#bit BRG16 = 0xFAA.3 // 16bit baud rate enable bit (1-16bit, 0-8bit)
#bit SPEN = 0xFAB.7 // Serial Port Enable bit (1-enable RX/TX, 0-disable)
#bit TX9 = 0xFAC.6 // 9bit Transmit Enable bit (1-9bit, 0-8bit)
#bit TXEN = 0xFAC.5 // Transmit Enable bit (1-enable, 0-disable)
#bit SYNC = 0xFAC.4 // USART Mode Select bit (1-sync, 0-async)
#bit BRGH = 0xFAC.2 // Baud Rate Select bit (1-high speed, 0-low speed)
#bit TRMT = 0xFAC.1 // TSR Status bit (1-empty, 0-full)
#bit RX9 = 0xFAB.6 // 9bit Receive Enable bit (1-9bit, 0-8bit)
#bit CREN = 0xFAB.4 // Continuous Receive Enable bit (1-enable, 0-disable)
#bit FERR = 0xFAB.2 // Framing Error bit (1-error, 0-no error)
#bit OERR = 0xFAB.1 // Overrun Error bit (1-error, 0-no error)
|
Hope this helps. |
|
|
|
|
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
|