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

fgetc clarification

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







fgetc clarification
PostPosted: Thu Feb 21, 2008 4:29 am     Reply with quote

Code:

#include <16f877.h>
#fuses NOWDT,XT, NOPUT, NOPROTECT, BROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=n,bits=8,xmit=pin_C6,rcv=pin_C7,stream=GSM)//GSM

#INT_RDA
void SerialInt(void)
{
   RXd_Data[Write_cntr++] = fgetc(GSM);
}


in the code above, if the int_rda is triggered, will the RXd_Data[] receive all the data first before it will exit the interrupt? or it will get the data one at a time? thanks..
Ttelmah
Guest







PostPosted: Thu Feb 21, 2008 5:12 am     Reply with quote

The interrupt will trigger when there is _one_ character ready to be received. This single character is all that the interrupt will receive. In computer terms, the time between characters is an age. The hardware, only buffers a maximum of two characters, but if you want to ensure that if a second character arrives before the interrupt exits, it is retrieved without having to exit and re-enter the interrupt, then use:
Code:

#INT_RDA
void SerialInt(void)
{
   do RXd_Data[Write_cntr++] = fgetc(GSM);
   while (kbhit(GSM));
}

As a 'comment', how are you limiting the value in Write_cntr?. Remember that if (for instance), you are looking for a particular character to say that the input has finished, and reset the counter, what happens if this character does not arrive?. As written, Write_cntr, could potentially overwrite the wole of the RAM memory, and crash the system radically. Look at how the buffer addressing is done in ex_sisr.

Best Wishes
Guest








PostPosted: Thu Feb 21, 2008 8:45 pm     Reply with quote

hi Ttelmah.. what i did was connect my 16f877 kit to a sim 300 gsm module.. so if the microcontroller receives something from the gsm module, the int_rda interrupt will be triggered.. my question is will this code:
Code:

#INT_RDA
void SerialInt(void)
{
   RXd_Data[Write_cntr++] = fgetc(GSM);
}

get all the messages from the gsm module before exiting the interrupt or it will get 1 character then exit and reenter the interrupt again for the next character?

thanks..
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Feb 22, 2008 2:48 am     Reply with quote

Ttelmah wrote
Quote:
The interrupt will trigger when there is _one_ character ready to be received. This single character is all that the interrupt will receive.

Because another character could be in the hardware buffer most often there will not be but if there is it will only be exactly one extra character Ttelmah was kind enough to show you how to retrieve it if it was there. His code tests
kbhit() and if the extra char is there it gets it. Subsequent characters arriving will trigger the interrupt. The asynchronous nature of RS232 is often misunderstood. PC's have massive buffers so they are rarely overrun so the asynchronous nature of RS232 is hidden.. A basic PIC INT_RDA Interrupt service routine gets a single char and moves it to a buffer ( circular since if it does not wrap around it will invade memory used for other variables). In this way with a smaller buffer the asynchronous nature of RS232 is accommodated just as it is behind the scenes in a PC. The PIC hardware typically has captured a single char issued an interrupt and is potentially processing a second. In the situation in which it may have completely received the second character Ttelmah's code will get it for you.
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