![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
weg22
Joined: 08 Jul 2005 Posts: 91
|
#INT_RDA and PIC16F87 |
Posted: Thu Apr 06, 2006 4:37 pm |
|
|
To solve my problem mentioned earlier, it was suggested that I use the RDA interrupt to determine when data is coming in from my GPS device. I am just doing a simple test, and cannot get it to work for some reason. I am using a PIC16F87 and my code is below...someone please help. It successfully prints the word "Start", but that it. I guess the interrupt is never triggered for some reason?
Code: |
#include <16F87.H>
#include <stdlib.h>
#define LED PIN_A2
#fuses HS,NOWDT,NOPROTECT,PUT,NOLVP
#use delay(clock=10000000)
#use rs232(baud=4800, xmit=PIN_B5, rcv=PIN_B2, stream=GPS)
#use rs232(baud=4800, xmit=PIN_A1, rcv=PIN_A0, stream=PC)
#int_rda
void isr()
{
char c;
// Read char from GPS device
c = fgetc(GPS);
// Send char back to the PC.
fputc(c, PC);
}
//---------------------------------------------------
main()
{
printf("Start\n\r");
// Enable the USART receive interrupt.
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1)
{
output_high(LED);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Apr 06, 2006 5:15 pm |
|
|
You never send anything to the GPS so why would it send anything to you? |
|
![](templates/subSilver/images/spacer.gif) |
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Thu Apr 06, 2006 5:29 pm |
|
|
GPS engines generally transmit RS232 NMEA the moment they're turned on. Unless you are changing the GPSs settings, you only ever have to listen. At least that is how the one I currently design with works. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 06, 2006 5:33 pm |
|
|
Post your compiler version. |
|
![](templates/subSilver/images/spacer.gif) |
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Thu Apr 06, 2006 5:35 pm |
|
|
One problem you are going to run into is that when the RDA interrupt goes off, you receive a character at 4800 baud, then turn around and stay in the ISR to send another character out at 4800 baud. When you exit the routine and the ISR has cleaned up after itself, you almost certainly will have missed the next character.
You're either going to have to transmit it out faster or store it and then send it when the sentence burst is complete. |
|
![](templates/subSilver/images/spacer.gif) |
weg22
Joined: 08 Jul 2005 Posts: 91
|
|
Posted: Thu Apr 06, 2006 5:49 pm |
|
|
My compiler version is 3.147 (an old one, I know). I'm guessing by asking me to post my compiler version, the code looks okay?
Oh BTW, like rberek said, the GPS device starts transmitting NMEA data the instant you turn it on.
Last edited by weg22 on Thu Apr 06, 2006 5:50 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Storic
Joined: 03 Dec 2005 Posts: 182 Location: Australia SA
|
|
Posted: Thu Apr 06, 2006 5:50 pm |
|
|
I had a problem where I had the interupt causing me problems on the RS232 if I was using the soft(bit bangging) setup
Code: | //#use rs232(Stream=RS485,baud=9600,xmit=PIN_B1,rcv=PIN_B4,bits=8,enable=PIN_A7) //RS485 LAN
#use rs232(Stream=USER,baud=9600,xmit=PIN_B7,rcv=PIN_B6,bits=8,DISABLE_INTS) // PC connection
|
I ended up disabling the intrupt as above to fix my problem.
ANdrew _________________ What has been learnt if you make the same mistake? ![Wink](images/smiles/icon_wink.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 06, 2006 6:13 pm |
|
|
Quote: | My compiler version is 3.147 |
I looked at the .LST file for your version, and the problem is that it
doesn't create a hardware UART on pins B5 and B2. It creates a
software UART. This means you will not get an RDA interrupt.
This thread discusses the problem:
http://www.ccsinfo.com/forum/viewtopic.php?t=19455
I tried the suggestion in that thread to use pins C6 and C7 and
it doesn't appear to work with your version. The compiler just
gives an error message. If you have PCW maybe you can fix it,
or you may have to upgrade. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 06, 2006 10:24 pm |
|
|
If you don't PCW or PCWH, then you don't have the Device Editor
and you don't have the possibility of fixing it by editing the device file.
If so, then here is a demo program that shows how to make your own
putc() and get() routines if the CCS library code doesn't work.
To use this code, you enter the crystal frequency and the UART baud
rate in the #define statements below. At the start of main(), you call
the init_uart() function. Then use my_putc() to send a character and
my_getc() to receive a character. You can use printf() if you use the
re-direction feature to send output to the my_putc() routine.
The demo program below shows how to do that.
Code: |
#include <16F87.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#define FREQ_OSC 10000000
#define BAUD_RATE 4800
#use delay(clock = FREQ_OSC)
#byte PIR1 = 0x0c
#byte SPBRG = 0x99
#byte RCSTA = 0x18
#byte TXREG = 0x19
#byte RCREG = 0x1A
#byte TXSTA = 0x98
#bit TXIF = PIR1.4
#bit RCIF = PIR1.5
#bit CREN = RCSTA.4
//------------------------
// Wait for the hardware UART's transmitter
// to become ready and then send the specified
// character.
void my_putc(char c)
{
while(!TXIF);
TXREG = c;
}
//------------------------
// Wait for character to be available from the
// hardware UART's receiver and then return it.
// If there is an overrun error, then clear it.
char my_getc(void)
{
int temp;
int retval;
while(!RCIF);
temp = RCSTA;
retval = RCREG;
if(bit_test(temp, 1))
{
CREN = 0;
CREN = 1;
}
return(retval);
}
//-------------------------
void init_uart(void)
{
SPBRG = (FREQ_OSC / (BAUD_RATE * 16)) -1;
TXSTA = 0x26;
RCSTA = 0x90;
}
//======================================
void main()
{
char c;
init_uart();
printf(my_putc, "Hello World\n\r");
while(1)
{
c = my_getc(); // Get a char and echo it back
my_putc(c);
}
} |
If you want to test receiver interrupts, then substitute
the following code for the bottom part of the program.
Code: | #int_rda
void rda_isr(void)
{
char c;
c = my_getc();
my_putc(c);
}
//================================
void main()
{
init_uart();
printf(my_putc, "Hello World\n\r");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PICman
Joined: 02 Nov 2007 Posts: 26
|
|
Posted: Fri Jul 31, 2009 2:29 pm |
|
|
Thank you VERY MUCH PCM programmer !!!
I had a real problem trying to activate the silicon UART on a PIC16F88.
I started to read here and there and, - BOY - , I was discouraged to see - NOT AGAIN - a version issue !!!!
But I finally found your "manual override" code (INIT_UART, MY_GETC and MY_PUTC) and BINGO ! Everything worked perfectly !!!!
Again thank you ! _________________ The ideal electronic world: A place where the words VERSION and REVISION do NOT exist ! |
|
![](templates/subSilver/images/spacer.gif) |
muratmaman
Joined: 30 Jan 2010 Posts: 19
|
|
Posted: Mon Nov 08, 2010 3:21 am |
|
|
PICman wrote: | Thank you VERY MUCH PCM programmer !!!
I had a real problem trying to activate the silicon UART on a PIC16F88.
I started to read here and there and, - BOY - , I was discouraged to see - NOT AGAIN - a version issue !!!!
But I finally found your "manual override" code (INIT_UART, MY_GETC and MY_PUTC) and BINGO ! Everything worked perfectly !!!!
Again thank you ! |
I used to pic 16f886 that my problem i can not use same time INT_RDA and INT_RB, INT_TIMER1. INT_RDA works alone and INT_RB, INT_TIMER1 works alone as well. But when i would want to use all of them same time it does not works. What can be source of problem. _________________ I have been developing pic and other microcontroller. I would want to share and get experiment form this site |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Mon Nov 08, 2010 3:31 am |
|
|
You are spending too long in one or more of the interrupt handlers.
Remember that things like timer interrupts, INT_RDA, etc., reflect hardware events happening at intervals. You need to always handle the event, and get out _fast_, then do any processing in the main code, so that other events can be handled. In the example code here, simply the act of sending the byte 'out' again on a software UART, _will_ take as long as it takes for another character to arrive, so if the GPS sends reasonably fast, there will never be time to do anything else.....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
muratmaman
Joined: 30 Jan 2010 Posts: 19
|
|
Posted: Mon Nov 08, 2010 5:38 am |
|
|
Ttelmah wrote: | You are spending too long in one or more of the interrupt handlers.
Remember that things like timer interrupts, INT_RDA, etc., reflect hardware events happening at intervals. You need to always handle the event, and get out _fast_, then do any processing in the main code, so that other events can be handled. In the example code here, simply the act of sending the byte 'out' again on a software UART, _will_ take as long as it takes for another character to arrive, so if the GPS sends reasonably fast, there will never be time to do anything else.....
Best Wishes |
Could you please check my code and give me idea.
http://www.ccsinfo.com/forum/viewtopic.php?t=43833 _________________ I have been developing pic and other microcontroller. I would want to share and get experiment form this site |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Mon Nov 08, 2010 5:45 am |
|
|
No, because the problem will be in one (or more) of the interrupt handlers, which you don't show.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
muratmaman
Joined: 30 Jan 2010 Posts: 19
|
|
Posted: Mon Nov 08, 2010 6:04 am |
|
|
Ttelmah wrote: | No, because the problem will be in one (or more) of the interrupt handlers, which you don't show.
Best Wishes |
Code: |
#include "16f886.h"
#device *=16 ADC=10
#fuses INTRC_IO,NOWDT,NOPROTECT,NOPUT,NOLVP,NOFCMEN,NOMCLR, BROWNOUT // with internal oscillator
#use delay(clock=4000000)
#use rs232(baud=9600,uart1, parity=N, xmit=PIN_C6,rcv=PIN_C7, bits=8, errors, timeout=500, STREAM=ENCODER)
#byte PIE1 = 0x8c
#byte INTCON = 0x8b
//BYTE data[15]={0};
BYTE i = 0;
#INT_RDA
void RS232(void)
{
data[i] = getc();
}
#INT_EXT
void ext_isr()
{
if (!input(PIN_B0) )
{
// Interrupts are checked 6ms after to filter noise
delay_6ms();
//
}
}
#INT_TIMER1
void timer1_isr()
{
bit_set(int_events, event_int_timer1);
}
void main()
{
short bResult;
disable_interrupts(GLOBAL);
output_a(0b00000000); // motor pinleri A2 ve A3 1 olacak
output_b(0b00000001); // RB0(CRD_CON), RB4(ortak uç), RB5(switch), RB6(Manuel kilit), RB7(Kapı açık kapalı)
output_c(0b10011011); // RC7 (RX input), RC6 (TX output), RC3(SCL), RC4(SDA), RC5(motor pin output ), RC2 Buzzer, RCO ve RC1 saat içininput
output_e(0x00);
set_tris_a(0b00000000);
set_tris_b(0b00000001); // RB0(CRD_CON), RB4(ortak uç), RB5(switch), RB6(Manuel kilit), RB7(Kapı açık kapalı), RC2 Buzzer,
set_tris_c(0b10011011); // RC7 (RX input), RC6 (TX output), RC3(SCL), RC4(SDA), RC5(motor pin output ), RCO ve RC1 saat içininput
set_tris_e(0x00);
port_b_pullups(TRUE);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports( sAN0|VSS_VDD );
set_adc_channel(1);
setup_spi(FALSE);
setup_timer_1(T1_EXTERNAL|T1_CLK_OUT|T1_DIV_BY_1); // setup interrupts
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
setup_oscillator(osc_4mhz);
last_port_b = input_b();
bNotSleep = 1;
// Enable interrupts
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_RB);
enable_interrupts(INT_RDA);
enable_interrupts(INT_EXT);
SET_TIMER1(0);
#ignore_warnings 203
while(TRUE)
{
bNotSleep = 0;
#ignore_warnings none
sleep();
#asm
nop
#endasm
}
[quote]
Could you please rewiew and give me ide how can handle time on this code.[/quote] |
_________________ I have been developing pic and other microcontroller. I would want to share and get experiment form this site |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|