View previous topic :: View next topic |
Author |
Message |
ROBOTICAR
Joined: 28 Aug 2007 Posts: 45
|
RS232 problem |
Posted: Mon Jul 14, 2008 10:39 am |
|
|
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Mon Jul 14, 2008 11:07 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
ROBOTICAR
Joined: 28 Aug 2007 Posts: 45
|
|
Posted: Mon Jul 14, 2008 11:43 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
ROBOTICAR
Joined: 28 Aug 2007 Posts: 45
|
|
Posted: Wed Jul 16, 2008 2:53 am |
|
|
who can help me?
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? |
|
![](templates/subSilver/images/spacer.gif) |
ROBOTICAR
Joined: 28 Aug 2007 Posts: 45
|
|
Posted: Wed Jul 16, 2008 3:29 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed Jul 16, 2008 4:06 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: RS232 problem |
Posted: Wed Jul 16, 2008 5:17 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|