View previous topic :: View next topic |
Author |
Message |
Andre-Pretorius
Joined: 09 Mar 2010 Posts: 9 Location: South Africa, Klerksdorp
|
Interrupts not working |
Posted: Sun Apr 25, 2010 12:36 pm |
|
|
Can someone please tell me why my serial interrupt is not reacting. As soon as D3 goes low it sends the command wait for OK then activate the interrupt. But if data comes in on my serial port after this, the interrupt is not triggered.
Any ideas would be appreciated.
Code: |
#include <config.h>
int conf=0;
#include <functions.h>
int ii=0;
#int_RDA
void RDA_isr(void)
{
string[ii]=getc();
ii=ii+1;
output_high(PIN_D6);
}
void main()
{
setup_adc_ports(AN0_TO_AN3|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64);
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);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(true)
{
ii=0;
if (conf == 0)
SMSCONF();
if (!input(pin_D3))
{
disable_interrupts(GLOBAL);
disable_interrupts(INT_RDA);
printf("at+cmgs=0829554322\r");
delay_ms(150);
printf("hallo\x1a");
getOK();
output_high(PIN_D5);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
}
if (!input(pin_D0))
{
output_low(PIN_D6);
output_low(PIN_D5);
}
}
}
|
_________________ Andre Pretorius |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 25, 2010 1:25 pm |
|
|
Always post your PIC. Always post a compilable test program, that has
the #use rs232(), #use delay(), and other statements. Always post your
compiler version.
Quote: |
But if data comes in on my serial port after this, the interrupt is not triggered.
disable_interrupts(GLOBAL);
disable_interrupts(INT_RDA);
printf("at+cmgs=0829554322\r");
delay_ms(150);
printf("hallo\x1a");
getOK();
output_high(PIN_D5);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
|
You disable interrupts for a long time. Do you have the ERRORS
parameter in your #use rs232() statement ? If you don't have it, and
3 or more characters come in while interrupts are disabled, then the
hardware UART will lock up. You won't get any more characters.
That is probably the reason for your problem. (That's why I said you
should always post your full program with the #use rs232 statement). |
|
|
Andre-Pretorius
Joined: 09 Mar 2010 Posts: 9 Location: South Africa, Klerksdorp
|
|
Posted: Mon Apr 26, 2010 12:36 pm |
|
|
Thank you, that did the trick including the error in the rs232 line. One more question, the line I get back from my modem starts with +CDS. In the code I am looking for the D. Should this code work? Or do I need to clear the array before I go into the interrupt?
Code: |
string[ii]=getc();
ii=ii+1;
if (string[1] == "D")
{
output_high(PIN_D6);
}
if (string[2] == "D")
{
output_high(PIN_D5);
}
if (string[3] == "D")
{
output_high(PIN_D4);
}
|
_________________ Andre Pretorius |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 26, 2010 11:59 pm |
|
|
It's better if you create a circular buffer in the #int_rda routine.
Use the Ex_sisr.c file from CCS as an example:
Quote: | c:\program files\picc\examples\ex_sisr.c |
Then, in a while(1) loop in main(), check if a character is available
in the circular buffer. If so, call the routine to get it from the buffer.
Then put in some code to check if you get the desired sequence of
characters "+CDS". When you get that pattern, it means that your
desired message is coming in. So start putting the incoming
characters into an array. As you get the characters, look for the
"End of Message" character. I assume there will be one defined in
the protocol. When you get that character, then stop filling the array.
Finally, go process the data in the array. Display it or do something
with it. |
|
|
|