|
|
View previous topic :: View next topic |
Author |
Message |
samus111
Joined: 28 Aug 2014 Posts: 29 Location: Colombia
|
Problem with Rx UART port with GPS module |
Posted: Fri Aug 29, 2014 9:15 am |
|
|
Good day
I have a problem that still I have not been able to figure out what is the root of the problem. I want to communicate a Iridium GPS module with a PIC (does not matter the Pic family, I only need that be able to communicate, and that be the most small as possible) I attach the code:
Code: |
#include <16f628.h>
#include <string.h>
#fuses intrc, nobrownout, noput
#use delay (internal=4000000)
#use RS232(BAUD=9600,BITS=8,PARITY=N,XMIT=PIN_B2,RCV=PIN_B1)
#define GP2 PIN_B4
#define GP3 PIN_B3
void main(){
char tmp;
set_tris_b(0b00000010); // 0b00000100
INI:
delay_ms(3000);
output_high(PIN_B3);
puts("AT\r");
output_low(PIN_B3);
CHAIN:
tmp=getc();
if (tmp==75) {
goto SBDWT;
};
goto CHAIN;
SBDWT:
delay_ms(1000);
output_high(PIN_B3);
puts("AT+SBDWT=HOLA MUNDO\r");
output_low(PIN_B3);
CHAIN2:
tmp=getc();
if (tmp==75) {
goto CSQ;
};
goto CHAIN2;
CSQ:
delay_ms(1000);
output_high(PIN_B3);
puts("AT+CSQ\r");
output_low(PIN_B3);
CHAIN3:
tmp=getc();
if ((tmp<48)&(tmp>53)) {
goto SBDIX;
};
if (tmp==75) {
goto CSQ;
};
goto CHAIN3;
SBDIX:
delay_ms(1000);
output_high(PIN_B3);
puts("AT+SBDIX\r");
output_low(PIN_B3);
delay_ms(8000);
goto SBDIX;
}
|
The procedure is easy, I must to send commands to the module, and the module answer (This answer is very fast). This answer is important to me to analyze, and once I got the answer I am looking for, I send another command.
Practically the answer I search in the first two commands is a OK, the problem is, always, the PIC gets lost searching in the second command. I can not understand, the first and the second command structure are the same.
I have tried with three programmers, and with the next PICs: 16F628, 16F88, 16F886, 16F688, 18F2550, and even, now I am trying with a dsPIC33FJ128MC, but in all the PICs, the result is similar (some gets to the third command, others send me trash, etc, etc).
I am sure the problem is with the code. There must be a sentence or something that is wrong in this project. I think maybe the Buffer or the way how I am using the fgetc is having problems but I am not sure. I hope someone can help me, excuse for my english, but is not my native language. Thanks |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Aug 29, 2014 11:19 am |
|
|
Hi,
No offense, but your 'C' code is some of the worst I've ever seen posted on the forum in a long time..... As another user recently said "I found myself gently retching in the corner" while reading it.... Clearly, based on your posted code, you haven't spent a lot of time browsing the forum archives, or studying the CCS provided example programs, to try to learn 'proper' 'C' language coding......
First of all, can you post a link to the 'GPS' module that you are using. Before proceeding, we need to know the interface specifications, the baud rate, etc. Also, are you sure this is a GPS project? You code doesn't seem to be written to read/interpret typical GPS data. Frankly, it seems more like a GSM project to me.
As to your code, there are lots of problems. First, for reliable data reception via the hardware UART, you really should be using a serial interrupt to receive data. Look at the example program 'ex_sisr.c' to see how this is done properly. You also need to add the 'Errors' keyword to your #use rs232 directive to prevent the UART from locking up if an over-run condition occurs..... This has been covered many, many times before! You use of 'goto's' is really poor 'C' form, and should be avoided if possible. All of your 'goto's' can be replaced with other constructs, such as 'Do-While' loops..... Finally, your formatting is terrible. Learn to write code with proper indenting, so as to be easily readable.
Your #fuses are a bit on the light side. Many fuses default to the desired value, but for critical ones, I like to explicitly state them. Examples would be the 'NOLVP', and the 'NOWDT' fuses.
John |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Aug 29, 2014 12:57 pm |
|
|
In addition to all the above: Code: | if ((tmp<48)&(tmp>53)) {
goto SBDIX; | Not sure what you want to do here, but this is never going to work. How can a variable ever be smaller than 48 AND at the same time be larger than 53? Impossible...
Also, study the difference between the commands '&' and '&&'. |
|
|
samus111
Joined: 28 Aug 2014 Posts: 29 Location: Colombia
|
|
Posted: Fri Aug 29, 2014 1:12 pm |
|
|
ok |
|
|
samus111
Joined: 28 Aug 2014 Posts: 29 Location: Colombia
|
|
Posted: Fri Aug 29, 2014 1:12 pm |
|
|
sorry, I am a beginner in CCS codes, but I like that you be so honest, Ok I will take the changes you have advised me, I will run again the program and I will answer in few minutes, Thanks (the range error, was a modification that I made for look something, and I forgot to return it to it real value)
Last edited by samus111 on Fri Aug 29, 2014 1:21 pm; edited 1 time in total |
|
|
samus111
Joined: 28 Aug 2014 Posts: 29 Location: Colombia
|
|
Posted: Fri Aug 29, 2014 1:13 pm |
|
|
For other side, the device is not a GPS module, is a Iridium module (IRIDIUM MODULE 9603), so, this one only takes a message from a manufactured device, and send them to the Iridium network, for later, be received in a email account. In this case, I want to send the message :Hola Mundo. the device, first must be activated by the command "AT", after this, the device will answer with a OK, later, I must to write the message in the module memory, then, I must to send the command "AT+SBDWT:(my text is here)". With this, the Module will answer with a OK, and I have to go with the third command, but in this part, the PIC does not recognize the OK answer from the module. I will take in mind your tips, I will answer soon today.
Last edited by samus111 on Fri Aug 29, 2014 1:34 pm; edited 1 time in total |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Aug 29, 2014 1:40 pm |
|
|
Hi,
Just out of curiosity, why did you chose this for your topic title, "Problem with Rx UART port with GPS module", if this is not a GPS project?
Rather that reading the module communications requirements to us, please post a link to the exact module you are using, as requested in my 1st reply!
John |
|
|
samus111
Joined: 28 Aug 2014 Posts: 29 Location: Colombia
|
|
Posted: Fri Aug 29, 2014 1:57 pm |
|
|
You are right, the true is that, the message I send by the iridium network, the idea is to send a GPS coordinate obviously gotten through a GPS module (I will use the L70 quectel GPS module), that's why my project is a GPS position sender, but the first part, I try to communicate the module with the PIC , and I am having problems here. Thanks |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Aug 29, 2014 2:39 pm |
|
|
Hi,
OK, but you've now ignored two requests that you post a link to the module that you are interfacing to the PIC, so I'm going to abandon this thread. Without the requested data you are just wasting everybody's time. If you come here asking for help, you really should be willing to cooperate with any requests for additional information that are made.....
Good Luck!
John |
|
|
samus111
Joined: 28 Aug 2014 Posts: 29 Location: Colombia
|
|
Posted: Fri Aug 29, 2014 2:43 pm |
|
|
but I answered before, the module is a IRIDIUM 9603, that is its name, do you need that I attach a file?? |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Aug 29, 2014 3:36 pm |
|
|
Hi,
You've come here asking for our help, so you should make it as easy for us as possible to help you. That means if there are any pertinent documents to help us, you should post links so that we can easily find them. In this case, at a minimum, we would need to see the module datasheet so that we could verify the hardware interface. We would also need to see the (AT) command reference so that we could see how to 'talk' to the module, and make it work as intended. Your interpretations of these documents are not good enough, and we should not be expected to have to go search for them on our own.
John |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9220 Location: Greensville,Ontario
|
|
Posted: Fri Aug 29, 2014 4:09 pm |
|
|
As John says, we need more information...
one HUGE problem could be the 'interface'. Most, if not all GPS devices run on 3 volts and the PIC is a 5 volt device. That alone is a big problem !!
hth
jay |
|
|
samus111
Joined: 28 Aug 2014 Posts: 29 Location: Colombia
|
|
Posted: Fri Aug 29, 2014 4:18 pm |
|
|
ok Jhon, and sorry, I am new in this forum, and I need to learn the procedure, Thanks for you help:
here is the developer guide:
http://www.pacificrim.com.au/media/custom/upload/File-1383622151.pdf
I have the AT Acommands in a pdf file, but I do not know how share it here, there is a way?
I think the problem is some issue with the schmitt trigger, but I am not sure, how can I configure the schmitt trigger in my 16f688? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Fri Aug 29, 2014 4:22 pm |
|
|
The developers manual says the default RS232 data rate is 19200...not 9600
It also says the module acts as DCE. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
samus111
Joined: 28 Aug 2014 Posts: 29 Location: Colombia
|
|
Posted: Fri Aug 29, 2014 4:25 pm |
|
|
Of course, I set the baud rate to 9600 in the module before (that is the baud rate of the GPS module too) and I stored that baud rate in a user profile, so always when the device starts, is transmitting and receiving to 9600. |
|
|
|
|
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
|