|
|
View previous topic :: View next topic |
Author |
Message |
colin_turner99
Joined: 24 Nov 2005 Posts: 7
|
3.3V RS232 |
Posted: Tue Nov 21, 2006 10:22 am |
|
|
Hi
I have a pic running a 5V and have a GPS module that has 3.3V RS232
The GPS is putting the data on B0 and my code is as follows
Code: | if (kbhit(GPS)) {
fprintf(HOST, "%c", fgetc(GPS));
} |
Code: |
#use rs232(baud=9600,parity=N,rcv=PIN_B0,bits=8,stream=GPS)
|
Code: |
port_b_pullups(false);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,4,10);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RDA);
//enable_interrupts(INT_TIMER1);
//enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
|
All i get from the PIC is grabage
If i send Test text from the PIC all work ok
has anyone got experanice with 3.3v RS232?
Colin |
|
|
Ttelmah Guest
|
|
Posted: Tue Nov 21, 2006 11:14 am |
|
|
You don't give us much to work on.
What PIC?.
What GPS module?.
What is the RS232 statement for the 'HOST' comms?.
What compiler version?.
Best Wishes |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Nov 21, 2006 6:40 pm |
|
|
.....and more missing info:
- Is there a 3.3V to 5V convertor between the GPS serial output and the PIC input?
- Why is INT_RDA enabled? Is it possible you are simultaneously receiving data?
Most of all these questions would have been answered had you given a small but _complete_ example program (including the fuse settings, etc.) |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
|
colin_turner99
Joined: 24 Nov 2005 Posts: 7
|
|
Posted: Wed Nov 22, 2006 3:09 am |
|
|
Hi
The Pic i am using is a 16F88
Basically the pic sits inbetween the GPS module and another device and does some caluations on the GPS data before sending it throught the HOST uart
I dont use a 3.3V to 5V converter
Here is my full code
Code: |
#include <16F88.h>
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT, HS, NOPUT, MCLR, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, FCMEN, IESO
#use rs232(baud=9600,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8,stream=HOST)
#use rs232(baud=9600,parity=N,rcv=PIN_B0,bits=8,stream=GPS)
#define BufferLength 25
#define length 39
char GPS_code[] = "$GPRMC,";
int8 GPS_buffer[length];
int8 HostBuffer[BufferLength];
int8 HostRead=0;
int8 HostWrite=0;
int8 c=0;
int8 GPS_write=0;
int8 GPS_state = 0;
int1 GPS_done = FALSE;
#int_RDA
void RDA_isr()
{
HostBuffer[HostWrite] = fgetc(HOST);
if (HostWrite==BufferLength) {
HostWrite++;
} else {
HostWrite = 0;
}
}
#int_TIMER1
void TIMER1_isr()
{
}
#int_TIMER2
void TIMER2_isr()
{
}
void main()
{
port_b_pullups(false);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,4,10);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RDA);
//enable_interrupts(INT_TIMER1);
//enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
while(1){
//fprintf(HOST, "Test Test Test");
if (kbhit(GPS)) {
fprintf(HOST, "%c", fgetc(GPS));
}
}
}
|
|
|
|
Ttelmah Guest
|
|
Posted: Wed Nov 22, 2006 3:57 am |
|
|
You still don't say which GPS module. This is critical, because whether or not you can use a direct connection without a buffer, depends on three things. First, the Voh of the 3.3v device. Second the Vih of the PIC. Third the signal polarity of the module.
Now the input your are using on the 16F88, has a Vih, just over 2v (2v, or 2.05v, according to which line of the data sheet you believe). Does your GPS module guarantee to give this as it's Voh into this load?. If not, then extra circuitry will be needed to handle this.
The code you have, assumes that the module is generating the normal 'inverted' RS232 (signal idles high), which is normally used when driving a RS232 buffer. Some modules designed for internal use, instead develop the opposite polarity. Is the data output line of the module sitting 'high', when no data is being sent?. If not, then you need to add 'INVERT' to the GPS RS232 declaration.
The logic in the 'host' interrupt handler is hosed, and will stop the receive from pulling the data here. However this should not affect your current test. Basically, 'HostWrite', is going to permanently stay as '0'. The code should be:
Code: |
#int_RDA
void RDA_isr() {
HostBuffer[HostWrite] = fgetc(HOST);
//HostWrite must be incremented _before_ the test, or the buffer
//will overflow by one character, and the counter only wants to reset
//when the limit is reached.
if (++HostWrite==BufferLength) {
HostWrite=0;
}
}
}
|
Add 'errors' to the HOST RS232 declaration.
You should be aware, that if a receive interrupt occurs during the software reception of a character, this will garbage the data. Hence (given the input hardware buffer on HOST), use:
Code: |
while (TRUE) {
if (kbhit(GPS)) {
disable_interrupts(GLOBAL)
//You must not output more than one character in the recieve
//time, or overruns _will_ occur. Hence use putc
fputc(fgetc(GPS),HOST);
enable_interrupts(GLOBAL);
}
}
|
Best Wishes |
|
|
|
|
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
|