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

problem GETC();

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



Joined: 17 Mar 2015
Posts: 4

View user's profile Send private message Send e-mail

problem GETC();
PostPosted: Sat Mar 21, 2015 5:50 pm     Reply with quote

Hello, is there a way to receive multiple characters, as getc() allows only receive 3 characters ?
temtronic



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

View user's profile Send private message

PostPosted: Sat Mar 21, 2015 5:58 pm     Reply with quote

You need to use an ISR with a buffer. CCS supplies an example 'ex_sisr.c' in the examples folder.
The hardware UART only has a 2-3 byte buffer and if you do not read the data fast enough, an 'overrun' condition (error) will occour.
You also will need to add 'errors' to the use RS232(....options....) as well..

Jay
mohamed_amine



Joined: 17 Mar 2015
Posts: 4

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 21, 2015 6:26 pm     Reply with quote

thx Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun Mar 22, 2015 1:55 am     Reply with quote

Let me slightly expand on this.

Getc, only retrieves _one_ character.

However you can receive any number of characters with this. Just call it whenever a character is available.... It can receive thousands (billions) of characters.

There is then a total of typically 2.99999 characters of hardware buffering (depending on the UART involved - this is an example of why you always need to tell us 'what PIC', for some there is only 1.99999, while some of the 'bigger' PIC's have more). The .99999, is because there will be an overflow as soon as the shift register actually fills, but provided you read a character before this happens, a character that was almost totally received before this time will then be transferred correctly.

So, if you have not been calling it and characters have been arriving 'unread', there is a maximum of just under three characters, that may be waiting for you to read.

As Temtronic says, there is an example with the compiler ex_sisr.c which shows how to implement an interrupt driven larger receive buffer (must only be a 'binary' size 4,8,16,32 etc. bytes, with the code as posted). Study this.

There is also a similar buffer now available using the #USE RS232 declaration, by adding 'RECEIVE_BUFFER=xxx' to this. This will automatically create a receive interrupt handler and a buffer for you, but with the caveat that it throws the latest character if it overflows - beware....

You need to get your head round the fact that you are talking directly to the chip's hardware, with the limitations this brings. On the PC for example, the standard UART only has three characters of buffering, while the later 16550 UART (which 99% of PC's will have), has 16 characters of hardware buffering, while some modern chips have even more, yet write code in C, C#, VB etc., and you will have hundreds or even thousands of characters of buffering available. This is because the OS offers an interrupt driven serial buffer already written for you. On the PIC, you have to add this yourself, or tell the compiler to add this.
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