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

strange RS232 behaviour ?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
newby



Joined: 26 Sep 2004
Posts: 32

View user's profile Send private message

strange RS232 behaviour ?
PostPosted: Tue Mar 15, 2005 2:31 pm     Reply with quote

I have connected a GPS receiver with serial output (TTL) directly to a PIC 18LF2620 on RC7 (RX). The GPS output has high levels of 3 V and low Levels of 0 V as long as the PIC is not connected. The PIC is supplied by 3.3 V. If i connect the PIC, the low level of the GPS signal raises up to about 1.1 V. Whatīs that ?!? Why does the GPS signal changes its voltage if i connect the PIC ? The manual of the GPS receiver tells me that it is no problem to connect the GPS directly (without MAX drivers...) to a e.g. PIC.

Thatīs my 1st problem and probably also the reason for my 2nd problem.

The 2nd is, that the receive of the GPS data on the PIC is malfunctioning from time to time. That means sometime "nothing" comes into the RX buffer, sometimes only garbage and sometimes it works like it should...

I use a ceramic oscillator at 8 MHz (ICD says 8.05) and want to establish a 4800 baud connection to the GPS - that should not be a big problem... but it seems to be. Could it also be that the frequency is not stable enough for using RS232 ? Do i have to use oscillators instead of these smart ceramic oscillators ?

I also tried to use the "auto baud rate detection" module, but i could not find any clear information how to use it with CCS and it didnīt work just by setting it to "auto mode without waiting for 055 char".

Does anybody have an advice for me ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 15, 2005 2:43 pm     Reply with quote

Quote:
The PIC is supplied by 3.3 V. If i connect the PIC, the low level of the
GPS signal raises up to about 1.1 V. Whatīs that ?!?

To me, this implies that the PIC pin is configured as an output.
So you have two output pins fighting each other.

I suspect that you are setting the TRIS for port C, and it's not correct.

Post a small test program that shows the problem, and post your version
of the compiler. Show all statements such as #fuses, etc.
newby



Joined: 26 Sep 2004
Posts: 32

View user's profile Send private message

PostPosted: Tue Mar 15, 2005 11:50 pm     Reply with quote

..no thatīs not the problem, i have checked this already.
TrisC.7 ist set to 1 (input). But according to the data sheet of the PIC18F2620 it doesnīt matter, as soon as you enable the EUSART, the PIN is configured correctly - i tried this without setting TrisC.7 with standard and fixed IO, itīs all the same.

Iīm on a business travel today and will post the fuses and code as soon as iīm home again. I will also have to reduce the code to the "main problem", itīs too much code...

Thanks a lot !
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Mar 16, 2005 2:38 am     Reply with quote

Did you try pulling the GPS low ( Ex 20k resistor to ground)..and are the PIC and the GPS grounds tied together?
newby



Joined: 26 Sep 2004
Posts: 32

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 2:21 pm     Reply with quote

I have reduced the code to the following (i use PCWH 3.221):

Code:
#include <18F2620.h>
#device ICD=TRUE
#fuses HS,NOIESO,NOBROWNOUT,NOWDT,NOPUT,STVREN,NOLVP,NOFCMEN,NOXINST,NOPBADEN,MCLR,DEBUG
#use delay (clock=8000000)

#use rs232(baud=4800, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream = GPS_channel, ERRORS, BRGH1OK)
//setup_UART(UART_AUTODETECT_NOWAIT);
#use rs232(DEBUGGER, stream = debb)
#ZERO_RAM
#BYTE  RCREG = 0x0FAE
#BYTE  RCSTA = 0x0FAB

char     char_dummy, rs232_buffer[50];
int8     rs232_i, i;

#int_RDA
RDA_isr() {
   rs232_i++;   if (rs232_i == 50) {      rs232_i = 0;   }
   rs232_buffer[rs232_i] = RCREG;
}

void main() {
   //   setup_oscillator(OSC_8MHZ, 0);
   port_b_pullups(TRUE);
   setup_wdt(WDT_OFF);
   setup_comparator(NC_NC_NC_NC);
   setup_ADC_ports(NO_ANALOGS);

   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   while(TRUE) {
      i++;
      char_dummy = fgetc(GPS_channel);
      if (i == 50) {
         i = 0;
         fputc(char_dummy, debb);
      }
   }
}


Both the isr INT_RDA as the while loop in main recieves data, but garbage (from time to time, but quite often)... The data provided by the GPS is OK, ich checked it using the SIOW tool.

I have also tried to pull down the GPS Signal to GND by several resistor values, ranging from 1 kOhm up to 100 kOhm. But all what happens is, that the high & low level of the signal is shifted a bit (about 0.1 - 0-2 V)towards GND.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 4:59 pm     Reply with quote

PCM programmer wrote:
Quote:
The PIC is supplied by 3.3 V. If i connect the PIC, the low level of the
GPS signal raises up to about 1.1 V. Whatīs that ?!?

To me, this implies that the PIC pin is configured as an output.
So you have two output pins fighting each other.
I do agree this sounds like a hardware problem with two outputs connected. Are you sure you have connected the GPS Tx to the PIC Rx pins? I mean a cross connection, also called null-modem.......???
Thinking more about it, this is not very likely the case as you said you sometimes do receive data.

A problem in your test program is that you have both the ISR and the main routine read the USART receive register simultaneously. Now it all depends on luck which routine gets the character and sometimes both routines get the character. Totally unpredictable. Change this so that only the ISR reads the data, the main routine can read from the buffer filled by the ISR.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Mar 17, 2005 7:33 pm     Reply with quote

As well as the changes ckielstra suggested
I'd change
Code:
if (rs232_i == 50) {      rs232_i = 0;   }

to
Code:
if (rs232_i >49 ) {      rs232_i = 0;   }

Also initialize rs232_i to zero

You probably have done this already if not
I'd look to test if the PIC rx pin that is now tied to your GPS Tx pin is configured as an input. Try disconnecting the GPS which you know to work and see if the PIC rx pin will drive a voltage across the 20k resistor you have tied to GND. If it's 3v its an output if its zero its probably an input but could be an output putting out zero. In case it could be pulling low tie the 20k to 3v and see if it actually does pull low.
newby



Joined: 26 Sep 2004
Posts: 32

View user's profile Send private message

PostPosted: Thu Mar 17, 2005 11:49 pm     Reply with quote

the above code is only "quick and dirty" to show the problem. If garbage is recieved than not only 1 of 100 chars, itīs more than up a certain point it comes only garbage... and then it functions again (that can change in minutes or i have to "wait for an hour"...)

I use #zero ram, therefore all variables are set to 0 at startup.

How could the RX PIN be set to output when using the EUART ? I have tried already playing around with the TrisC register but it doesnīt change anything. In the datasheet of the 18F2620 is also mentioned that enabling the EUART will auomatically configure the RS232 pins... But nevertheless i will try your suggestion ! Thank you !
newby



Joined: 26 Sep 2004
Posts: 32

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 12:02 am     Reply with quote

@ckielstra:
the above code is only "quick and dirty" to show the problem, itīs clear that it does "not function" in a way to receive a complete GPS data set.

In my program i use the isr to fill the buffer. I found out that sometimes the INT_RDA is not started even there are some chars which can be got using fgetc(). Which is indeed also very strange (to me)?
The Pic receives somewhat which can be polled using the getc functions, but it doesnīt start an INT_RDA... That is why i implemented both ways to look if this strange isr problem occurs again.

I will check my wires again very carefully. At the moment i can only say that the RX from PIC is directly (just on wire) connected to the TX from GPS, i donīt use the TX from PIC and the RX from the GPS. But that shouldnīt be a problem (it has also worked before...).
I guess if there would be a mistake, i would not be possible to receive (sometimes, for e.g. a couple of minutes) several complete and correct GPS data sets....
Ttelmah
Guest







PostPosted: Fri Mar 18, 2005 3:01 am     Reply with quote

You need _two_ wires to connect even one way RS232. The signal itself and the ground (another poster suggested looking at this). I suspect what is happening, is that you are perhaps relying on a ground 'through' a power supply, or other connection, and it is either not reliable, and/or the quality of connection changes with different hardware layouts, and is generating your problem.

Best Wishes
newby



Joined: 26 Sep 2004
Posts: 32

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 4:52 am     Reply with quote

Quote:
You need _two_ wires to connect even one way RS232. The signal itself and the ground

...i donīt understand this. The GPS uses the _same_ GND as the PIC, and that should not be enough to ensure that te GND potential is the same ?

How does it work anywhere else ?

Or do you mean because the GPS seems to have some kind of MAXxyz driver implemented, that the GND from the GPS after MAXxyz is floating ?!?

I will try this out and connect RX AND TX, thought that is not necessary (it hasnīt been till this project) !

Thankīs a lot, hope thatīs it !
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Fri Mar 18, 2005 8:10 am     Reply with quote

The description of this issue seems confusing. The poster says the GPS has TTL output built in and if I read correctly the poster says it can also talk to the PC RS232 port and send data correctly according to the poster ( using SIOW) without a second level converter ( max 232 eg) Presumably the poster is selecting invert bytes in the SIOW menu. Now it maybe the posters voltage measurements are made with a VOM while the GPS is transmitting in which case they would represent an average voltage.
Now the UART port has a hysterisis so it might be that the UART which waits for a start bit before kicking into action is not seeing most start bits.
The PC hysterisis will be markedly different since it is expecting true rs232 and will see zero or less as a mark.
The poster says the PIC is has a 3v supply but I see NOLVP in the fuses setting.
The GPS supply is probably also at 3v but if its 5V it maybe the cause of the problem.
newby



Joined: 26 Sep 2004
Posts: 32

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 10:53 am     Reply with quote

@Ttelmah
I have connected RX and TX, it didnīt change anything.

@Douglas Kennedy
The GPS modul is powered with 5V, the PIC with 3.3 V. The RS232 Signal from the GPS has (without PIC) a high level of 3 and a low level of 0 V. I donīt know what a "VOM" is, i use a oscilloscope. Yes the GPS can provide TTL as "RS 232" levels - says the description and it "works/ed".
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 11:06 am     Reply with quote

Can you post the manufacturer and part number of the GPS unit,
and a link to the data sheet if possible ?
newby



Joined: 26 Sep 2004
Posts: 32

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 12:00 pm     Reply with quote

Unfortunately i couldnīt find a datasheet, but here is the description http://www.fortuna.com.tw/U2.htm.

Iīm "redesigning" my test bed at the moment to test it with PIC and GPS both running at 5 V.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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