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

RS232 problem

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



Joined: 28 Aug 2007
Posts: 45

View user's profile Send private message

RS232 problem
PostPosted: Mon Jul 14, 2008 10:39 am     Reply with quote

Hi All
I'm working with GPS module . this module is sending data all the time. I want get the string and process it but I cant . for example I write a very simple program to get data:
Code:


int j[90];
#INT_RDA
isr()
{
  gets(j);
  puts(j);
}
void main()
{
   

    enable_interrupts(GLOBAL);
    enable_interrupts(INT_RDA);

}


when I test this code in proteus I get the result . but when I was test it with GPS module PIC just get and print the first string. so whats the problem ?
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Mon Jul 14, 2008 11:07 am     Reply with quote

First of all, j is not initialized to any value so it could contain anything. Second, everytime a character is received you are storing it in the same place as the previous character. You need to initialize j to be zero and then increment it each time a character is saved. Then, when all of the characters have been received you need to add a NULL at the end since it is to be a 'string'.

Ronald
ROBOTICAR



Joined: 28 Aug 2007
Posts: 45

View user's profile Send private message

PostPosted: Mon Jul 14, 2008 11:43 am     Reply with quote

thanks but I think the micro will be hang with this code.
Code:

#define LED PIN_A0
int j[90];
#INT_RDA
isr()
{
  gets(j);
  puts(j);
}
void main()
{
   

    enable_interrupts(GLOBAL);
    enable_interrupts(INT_RDA);
    while(1)
    {
         delay_ms(1000);
         output_toggle(LED);
    }

}


I just add a while loop. In this loop one led become ON and OFF but after print the first string this LED didn't OFF and I think the Microcontroller hanged. I test this code with the 'COM PORT' and 'KEYBOARD' and get correct result but when use it for gpd module it doesn't work. I think the speed of transfer data with this module is very high (baud rate=9600)
and micro can't process it. What can I do to get data and string from this module?
ROBOTICAR



Joined: 28 Aug 2007
Posts: 45

View user's profile Send private message

PostPosted: Wed Jul 16, 2008 2:53 am     Reply with quote

who can help me? Confused Confused
this code work with PC correctly but doesn't work with module because it is very fast . How can I get data with the module that send data very fast?
ROBOTICAR



Joined: 28 Aug 2007
Posts: 45

View user's profile Send private message

PostPosted: Wed Jul 16, 2008 3:29 am     Reply with quote

after get first string my KBHIT() become TRUE and then I can't keep on to get data . what can I do for make kbhit() false?
Ttelmah
Guest







PostPosted: Wed Jul 16, 2008 4:06 am     Reply with quote

Try some searching here. There are literally hundreds of threads here about this type of thing. However, some 'basics':

INT_RDA triggering, implies there is _one_ character waiting to be read. Only one. You then call 'gets', which will sit and wait to read an entire line of data. As soon as you do this, the processor is now locked inside the interrupt handler.
Fetch just the _one_ character.
Look at EX-SISR, for an example of how to fetch, and buffer characters.

Having done this, you then call 'puts'. This outputs the whole string, taking just as long again. Even worse, while this is going on, if any character is received, it cannot be handled, since you are still inside the handler. You don't show your RS232 setup, but unless this includes the keyword 'ERRORS', your hardware _will_now be hung.

Best Wishes
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: RS232 problem
PostPosted: Wed Jul 16, 2008 5:17 am     Reply with quote

Just to emphasize what Ttelmah said, you should not call gets() in an ISR. gets() gets an entire string, up to a terminating character. An ISR must return after each character.

Also, your main() program runs off the bottom. You must not let it do this.

Actually, there is no reason that you have to use interrupts at all. You could just read the string in one character at a time by polling. Then, after the string is read in, do whatever you need to do to analyze it. The GPS strings have plenty of time between them, so you don't need to be watching for the next string until you have finished processing the current string.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
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