|
|
View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
interrupts questions |
Posted: Tue May 06, 2008 11:57 am |
|
|
Hi
I dont used interrupts but I need very much start use, because that I ask your help...
for example using an 18F452 how make one test program where print "Hello World" on hiperterminal when I write on terminal "A"?
I make this wizard this is correct?:
Code: |
#include "main.h"
#int_RDA
void RDA_isr(void)
{
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
}
|
main.h:
Code: |
#include <18F452.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOCPD //No EE protection
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#use delay(clock=20000000)
#use rs232(baud=11500,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
|
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed May 07, 2008 10:08 am |
|
|
Hi
more one time thanks for your help PCM Programmer
now I have interrupts work but appear 2 problems...
this is my code:
Code: |
#include <18F252.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=4800, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=tlmport)
#use rs232(baud=4800, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8, stream=gpsport)
#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
nop
#endasm
} // Reserve space for the bootloader
#int_rda
void rda_isr(void)
{
char c, string[61];
int i,k;
c=getc(gpsport);
if (c=='C')
{
i=0;
k=0;
do
{
c=getc(gpsport);
i++;
string[i]=c;
}while(c!='*');
i=i-1;
fprintf(tlmport, "array size: %u\n\r",i);
//$GPRMC,161229.000,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10
for(k=2;k<=12;k++)
{
fprintf(tlmport, "time: %c\n\r",string[k]);
}
}
}
void main ()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1)
{
printf("wait for first character \n\r");
delay_ms(1000);
}
}
|
this work fine if I dont have 2 rs232...
the interrupt work with rs232 "gpsport"?
is possible write string which PIC read without "for cicle"?
In this case I think write "161229.000" but I stay write this in charaters dont is possible write complete string "161229.000"?
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 07, 2008 11:43 am |
|
|
#int_rda only works with the hardware UART, which is on pins C6 and C7. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed May 07, 2008 1:27 pm |
|
|
Hi
I change this on the code and interrupts stop working...
I change this:
Code: |
#use rs232(baud=4800, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, stream=gpsport)
#use rs232(baud=4800, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8, stream=tlmport)
......
c=getc(gpsport);
if (c=='$')
{
i=0;
k=0;
do
{
c=getc(gpsport);
i++;
string[i]=c;
}while(c!='*');
|
I think with my code when "gpsport" recive '$' save the string until '*' and after write on "tlmport" 1.ºs ten caracters, but if don't receive character '$' it write "wait for first character"...
and on terminal I see "wait for first character" I think with interrupts don't work...
for example:
if I make a simple program like that:
Code: |
while(1)
{
c=fgetc(gpsport);
fputc(c,tlmport);
}
|
result is strange characters like that:
Quote: |
¤°°µ¬¤¬¶Ã‹ÍS¤ƒ³c¶°¸±sS¤ƒµc¶äËk¤S¤‹¹»³#°›¬¤¬¶°¸±sS¤ƒ¹c¶°¸±sS¤ƒ
²c¶4Ëk¤¬¬ª¤°°¸¬¤¬¶ƒÃ‹k¤S¤ƒ¸c¶¤°¸lŽc¬5‹¹»¹#°‹S#k·ƒÃ‹k¤S¤ƒµc¶°¸±sS¤ƒ
°c¶dËÍS¤ƒ³5Z® °¸±sS¤ƒ±5ZnƒÃ‹k¤S¤‹¹»·#°³¬¤¬¶¤°¸lŽc¬5ƒ²5Z. dËÍS¤ƒ°
c¶ƒÃ‹ÍS¤ƒ¹c¶ƒÃ‹k¤S¤ƒ¹c¶
|
what I make for correct that? have some idea?
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 07, 2008 1:44 pm |
|
|
Describe the connections between pins C4 and C5 on the PIC, and your PC.
Do you have a MAX232-type chip connected between the PIC and the PC ? |
|
|
Guest
|
|
Posted: Wed May 07, 2008 1:59 pm |
|
|
Quote: |
Describe the connections between pins C4 and C5 on the PIC, and your PC.
Do you have a MAX232-type chip connected between the PIC and the PC ? |
Hi
on pins I have:
C4-recive pin of my cable
C5-transmit pin of my cable
C6-recive pin of GPS
C7-transmit pin of GPS
on pin C7 I use an transistor, 2 resistor and one diode for limit voltage, because GPS signals go until 9V and transistor limit this on 5V, but this part before I change program work fine.
I use cable interface usb to rs232 and when I use the 1º program it work perfect. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 07, 2008 2:14 pm |
|
|
How do pins C4 and C5 connect to the PC ?
Do you use a USB-to-RS232 cable for pins C4 and C5 ?
If so, you must add a MAX232-type chip between the PIC and the
USB-to-RS232 cable. Example:
Code: |
PIC <---> MAX232 <---> USB-to-RS232 cable <---> PC
C4,
C5 |
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed May 07, 2008 2:35 pm |
|
|
Hi
sorry for I respond witout login :S
PIC <---> MAX232 <---> USB-to-RS232 cable <---> PC
C4 <---------------------> USB-to-RS232 cable <--->RX CHIP PL-2303
C5 <---------------------> USB-to-RS232 cable <--->TX CHIP PL-2303
I dont use MAX232 because I dont need this because I use mobile phone cable with chip "PL-2303 USB-to-Serial Bridge Controlle".
if you have this program how you think better make this connections?
I need to rs232 ports, one for GPS and other for see results on PC.
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 07, 2008 2:44 pm |
|
|
Where is the PL-2303 located ? Is it in your PC ? Is it on a board ?
Is it in the GPS ? |
|
|
Ttelmah Guest
|
|
Posted: Wed May 07, 2008 2:50 pm |
|
|
You are missing the point.
The PIC generates _TTL_ serial.
The PC, or your USB adapter, generate RS232 serial.
To talk to RS232 serial, the PIC, _needs_ an inverter and level translator (normally the MAX232). It _does not_ talk directly to RS232 serial levels.
You need the MAX232 between the PIC, and your PL2303.
Best Wishes |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed May 07, 2008 3:12 pm |
|
|
Hi
pl-2303 stay under de cable USB-serial... this cable dont need max because it work TTL levels 3.3V
and I always use this cable for program (from bootload) and communicate with PIC, I think which dont stay in cable but yes on program or something..
because if I dont use 2 rs232 ports it work fine...
you suggest I make some test for you see if I have my connections correct?
for example if a make one program with:
fprint(tlmport, "mobile phone port \n\r");
fprint(gpsport, "gps port \n\r");
when I put cable on tlmport(pin C4 and C5) I get string "mobile phone port" if I put cable on gpsport(pin C6 and C7) I get string "gps port"...
because that I think which I have my connections correct, and the problem dont stay on cable...
is possible problem stay on oscillator? I have 20MHz dont is required 40Mhz?
thanks |
|
|
Ttelmah Guest
|
|
Posted: Thu May 08, 2008 2:01 am |
|
|
I'm sorry, but you are wrong. The PL2303, _does_ require an inverter chip between it and the PIC.
Best Wishes |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Thu May 08, 2008 3:11 am |
|
|
Hi
so, why it work fine if I put GPS port on C4 and C5 and serial port on C6 and C7 (disable interrupts)?
this happen when I change ports order.. I dont understand that... |
|
|
Ttelmah Guest
|
|
Posted: Thu May 08, 2008 5:11 am |
|
|
In your diagram of your wiring, you don't show the GPS at all.
Now, key is to understand, that there are three 'separate' parts of async serial signalling, which (unfortunately), are often mistitled/used (by CCS for example).
RS232, is a signalling standard, defining what voltages are used for a '1', and a '0', and the current drive abilities of the bus etc..
Then there is the character protocol. So (say), 2400bps, 8bits, no parity, one stop bit.
Finally, there is the data protocol, which defines what order things are sent in the data stream.
So a full 'GPS', offering NEMA protocol, at 2400N81, over RS232, tells you what each of these parts comprise. The problem is that you get things like GPS 'modules', meant for inclusion inside a sytem, which are mislabelled, and refer to 'RS232', when they don't use RS232 signalling, but instead use inverted _TTL serial_ signalling. The same error is made by CCS, in their '#USE RS232' statement, since the PIC itself also generates this inverted TTL signalling, _not_ 'RS232' signalling. This is why you still use the '#USE RS232' command, for RS485 signalling, but just change the driver chip being used.
Now, the point is that the PL2303, produces a subset of RS232 signaling (actually RS232, but using a lower voltage than the original specification. As such, it produces signals _inverted_ from those required by the PIC inputs. If you have a GPS module that will connect directly in it's place, then the odds are that this produces async TTL serial, which has the signals the right polarity for the PIC connections.
Now, the software serial, can produce signalling the right polarity to connect directly to 'RS232' (using the 'invert' keyword - slightly confusing, since the signal is then 'positive logic'), but the hardware serial can't.
You need to simplify your testing, and get your connections right, _before_ trying to use two connections.
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
|