|
|
View previous topic :: View next topic |
Author |
Message |
andys
Joined: 23 Oct 2006 Posts: 175
|
multiple uarts with gps |
Posted: Wed May 08, 2013 2:05 am |
|
|
I need to use 2 Uart channels. The first to communicate with an gps and the second for the printing the results at the screen.
My problem is how to use the uarts.
For a example if i need to use puts("xxxxx");
How to define which one of the uart is responsible to print this?
(I mean how the compiler know if the "puts" command is going to execute by the GPS's uart or to the pc's uart) |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed May 08, 2013 2:49 am |
|
|
I found this in the CCS manual Quote: | How can I use two or more RS-232 ports on one PIC®? |
Followed by an example of how to do it.
Mike |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed May 08, 2013 2:04 pm |
|
|
Right...
You would use "streams" and then fprintf or fputs (and all the other fxxxx funtions for input/output)
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed May 08, 2013 3:17 pm |
|
|
&&
in case of confusion,
make sure it is a pic with DUAL hardware EUSARTS
( far fewer of these than single serial eusart pics)
as software RS232 is really not going to bring any joy......... |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed May 08, 2013 4:25 pm |
|
|
asmboy wrote: | &&
in case of confusion,
make sure it is a pic with DUAL hardware EUSARTS
( far fewer of these than single serial eusart pics)
as software RS232 is really not going to bring any joy......... |
Also -- a must.
A bunch of the PIC18's have them. I'm not sure about the PIC16 series. I think some do...
Anyway -- look for dual EUSARTs -- they definitely make life a LOT easier. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Wed May 08, 2013 5:59 pm |
|
|
I've been using the 18F46K22 for about a year...2 UARTs,lots of memory,tons of peripherals, etc. |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
multiple uarts with gps |
Posted: Sun May 12, 2013 7:57 pm |
|
|
I used the code bellow and circuit
( http://obrazki.elektroda.pl/8875379500_1368409736.png) .
I used the dspic33fj64gp202
I expecting to receive the data from GPS and print them to pc's screen.
Unfortunately nothing appear
Is anyone who have any ideas what is going wrong ?
First of all the connectivity diagram is correct?
Code: |
#PIN_SELECT U1TX=PIN_B14
#PIN_SELECT U1RX=PIN_B15
#USE RS232(UART1,ERRORS,BAUD=9600,STREAM=COM_A)
#PIN_SELECT U2TX=PIN_B13
#PIN_SELECT U2RX=PIN_B12
#USE RS232(UART2,ERRORS,BAUD=4800,STREAM=COM_B)
int main()
{
char comandGPR[10];
fprintf(COM_A,"Online\n\r");
while(TRUE)
{
fputs("HELLO", COM_A);
fgets(comandoGPR,COM_B);
fputs(comandoGPR ,COM_A);
delay_ms(1000);
}
return 0;
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Mon May 13, 2013 2:13 am |
|
|
You don't show us your fuses/clock settings, so we can't tell if there might be a problem here.
Compiler version?.
Generally, when using selectable pins, you need to specify the TRIS yourself.
As a comment, get rid of the return at the end of the main, and the int declaration. The main has nowhere to return 'to', and cannot return a value (this is why it should be declared as void). It is never called by an OS like a normal C program, it _is_ the entire code.
Most GPS's return strings that are longer than 10 characters. Are you sure your buffer is large enough?.
Typing error 'comandGPR', versus 'comandoGPR'. Doesn't give confidence this is what you are actually trying...
Your should turn off the analog functions, and any fixed peripherals on the pins. These have priority over re-mappable functions.
Test the UART's individually first. Do a simple 'hello world' type output on each. Then once you know it is transmitting, try an input on each.
Best Wishes |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon May 13, 2013 6:28 am |
|
|
Hi,
Your hardware is wrong. First of all, your schematic is really horrible. A schematic should not only document the components, and the electrical connections used, it should show "how" things are connected. Lack of simple nomenclature symbols on your parts (eg. 'TxD' and 'RxD') on your schematic forces the reader to constantly refer to outside references like datasheets. A schematic should 'enlighten', and not 'confuse', which is what yours does.....
Your schematic has at least two fatal errors that I can find at a quick glance. The first is that the PC serial port connections are reversed, assuming that you aren't using a 'null modem' serial cable. This is the same error you made months ago when you were trying to get your dsPIC33 working with RS232 (hence our frustration that you aren't learning anything....). The second error is that one of your PIC TX outputs is connected to a MAX232 receiver output.
Here is a pretty good tutorial on UARTs and serial communications:
https://www.sparkfun.com/tutorials/104
John
Last edited by ezflyr on Mon May 13, 2013 5:40 pm; edited 2 times in total |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon May 13, 2013 10:07 am |
|
|
a quick comment
i NEVER use gets() || fgets()
so quoting the CCS doc:
Quote: |
Reads characters (using getc()) into the string until a RETURN (value 13) is encountered. |
unless you spec a timeout value in #use rs232
the above mentioned call is a potential deadlock
that a good programmer will avoid like the plague that it is
|
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
multiple uarts with gps |
Posted: Mon May 13, 2013 5:33 pm |
|
|
Ttelmah,
I have already test individual the rs232 connections between PC and microcontroller and is working fine.
For example if I put as comment the fgets/fputs which are relative to COM_B (GPS) everything is working fine.
Code: |
fprintf(COM_A,"Online\n\r");
while(1){
fputs("HELLO", COM_A);
//fgets(comandoGPR,COM_B);
//fputs(comandoGPR ,COM_A);
delay_ms(1000);
}
|
So my problem is not at the clock settings, or is not need the TRIS command.
When I define a char comandoGPR[10]; and then with fgets(comandGPR,COM_B); I expect to read 9 character string which is generated by the GPS.(I know that the GPS with NMEA ptotocol will generate more that 9 characters) but with the command fputs(comandGPR ,COM_A); I expect to see something to the rs232 screen.
Finally if the COM_A rs232 is working then the compiler version is ok.(Correct me if I am wrong)
Asmboy,
I don’t know how to read/write a string with the fputc. (I always use the fputs/fprintf)
I modified the code so to read a character from the GPS and write it to the screen (at the moment I need to see something from the GPS – to know that the communication between GPS and microcontroller is working)
I use the code bellow :
Code: |
while(1)
{
fputs("HELLO", COM_A);
comandoGPR=fgetc(COM_B);
fputc(comandoGPR, COM_B);
}
|
|
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
multiple uarts with gps |
Posted: Mon May 13, 2013 5:34 pm |
|
|
Ttelmah,
I have already test individual the rs232 connections between PC and microcontroller and is working fine.
For example if I put as comment the fgets/fputs which are relative to COM_B (GPS) everything is working fine.
Code: |
fprintf(COM_A,"Online\n\r");
while(1){
fputs("HELLO", COM_A);
//fgets(comandoGPR,COM_B);
//fputs(comandoGPR ,COM_A);
delay_ms(1000);
}
|
So my problem is not at the clock settings, or is not need the TRIS command.
When I define a char comandoGPR[10]; and then with fgets(comandGPR,COM_B); I expect to read 9 character string which is generated by the GPS.(I know that the GPS with NMEA protocol will generate more that 9 characters) but with the command fputs(comandGPR ,COM_A); I expect to see something to the rs232 screen.
Finally if the COM_A rs232 is working then the compiler version is ok.(Correct me if I am wrong)
Asmboy,
I don’t know how to read/write a string with the fputc. (I always use the fputs/fprintf)
I modified the code so to read a character from the GPS and write it to the screen (at the moment I need to see something from the GPS – to know that the communication between GPS and microcontroller is working)
I use the code bellow :
Code: |
while(1)
{
fputs("HELLO", COM_A);
comandoGPR=fgetc(COM_B);
fputc(comandoGPR, COM_B);
}
|
What do you think?
Ezflyr,
I don’t understand why your so offensive against me.
I am not a professional programmer of dspic and I try to programming when I have a free time from my work just for hobby. (If you don’t want to involve at my question just don’t do it).
Btw you said that the connections are wrong but (at least the connection between microcontroller and pc ) is working. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue May 14, 2013 12:50 am |
|
|
Seriously you are missing the point about the length of the buffer. gets, has no limit at the length of the buffer. If any string arrives from the GPS, that is longer than 9 characters, the data will be written into the ram of your chip overwriting other variables, and the code will go wrong/stop working. A 'string' requires one more character of storage than the actual length expected, so you must make your buffer longer than the longest string you may receive from the GPS, to have any hope of it working.....
Use input.c and the get_string function, and limit this to 9 characters, or expand the buffer to 256 characters (nmea has a limit on the maximum line length at 255 characters).
There is a secondary major problem that with the huge delay, enormous amounts of data will be lost. Remember only a couple of characters of buffering in the UART, and the GPS will keep sending all the time. Why delay?. the code waits for the message from the GPS.
Then you say you have tested the RS232. Have you remembered the null modem wiring needed to attach a port on the PIC that talks OK to the PC, to a GPS that also talks OK to a PC?.
You are going to need to look at using buffered serial receive (ex_sisr.c), to have any hope of this working properly in the future.
Best Wishes |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue May 14, 2013 9:25 am |
|
|
Hi andys,
I'm sorry, you are right, I should tone down my comments or not post at all. Lately, it seems like there are so many posts by people who don't want to do any work (I'm NOT referring to you here!), and that colors my mood when posting! Again, sorry for my earlier comments!
In addition to what Ttelmah says about your code, you definitely have some hardware problems! The PC connection is "non-standard", but it will work if you are using a "null modem" cable, which swaps the Tx and Rx connections internally. If this is working, and you can see data on your PC screen originating from the PIC, then don't worry about it!!
Your GPS, on the other hand, will not work as drawn in your schematic!! First, I assume your GPS has an RS232 output, and transmits/receives RS232 voltage levels. As drawn, the Tx output of your GPS is trying to drive the output of a MAX232 Tx driver. That's bad, and will not work! Here are the GPS/MAX232 connections you need:
GPS Tx ---> MAX232 Pin 8, and then Max232 Pin 9 ---> PIC Pin 6 (Rxd)
GPS Rx <--- MAX232 Pin 7, and then Max232 Pin 10 <--- PIC Pin 5 (Txd)
Once the hardware is working, we can help with the code.
If you are serious about working with electronics as a hobbiest, I would recommend that you take a look at the Cadsoft Eagle schematic and board layout software. I believe there is a free version for home/hobby use, and you can use it to vastly improve your schematics!! It will also allow you to design your own simple PCB's!
John |
|
|
andys
Joined: 23 Oct 2006 Posts: 175
|
multiple uarts with gps |
Posted: Fri May 17, 2013 5:29 pm |
|
|
Ok ezflyer I suggest to forget all these, I am sure that you hadn't any bad purpose.
Now according the thread I did the changes at the hardware and now I can see garbage to the screen. (This is an improvement , mean at least that something is transmitted ) . (I didn’t use any null modem i will buy when i find some free time).
Now according the software issues , is need to use interrupts ?
Also i tried to use the code front the example ex_sisr.c after Ttelmah suggestion but i can see only garbage at the screen |
|
|
|
|
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
|