|
|
View previous topic :: View next topic |
Author |
Message |
nicotec
Joined: 07 Nov 2008 Posts: 60
|
#int_rda with pic24fj16ga002 |
Posted: Mon Jan 26, 2009 9:06 am |
|
|
Can anyone please help me about receive serial data interrupt not working? Led on pin B7 is alway off when I send data on serial port.
Thanks, bye
Code: |
#include <24FJ16GA002.h>
#include <string.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOWRT //Program memory not write protected
#FUSES NODEBUG //No Debug mode for ICD
#FUSES ICS3 //ICD communication channel 3
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES WINDIS //Watch Dog Timer in non-Window mode
#FUSES WPRES128 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16 //Watch Dog Timer PostScalar 1:32768
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FRC //Internal Fast RC Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is general purpose output
#FUSES NOPR //Pimary oscillaotr disabled
#FUSES I2C1SELD
#use delay(clock=8000000)
#pin_select OC1=PIN_B0 //OUTPUT OF PWM PIN 4
#pin_select OC2=PIN_B1 //OUTPUT OF PWM PIN 5
#pin_select U1TX=PIN_B10 //RS-232 TX PIN 21
#pin_select U1RX=PIN_B11 //RS-232 RX PIN 22
#use rs232(UART1,baud=57600,parity=N,bits=8,stop=1)
#int_RDA
void RDA_isr(void)
{
output_high(PIN_B7);
}
void main()
{
long an_1;
long an_2;
long an_3;
int cmd;
int val;
char rec_str[30];
char rif_int;
char rif_fin;
setup_spi(SPI_SS_DISABLED);
setup_spi2(SPI_SS_DISABLED);
setup_wdt(WDT_ON);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
enable_interrupts(INT_RDA);
enable_interrupts(intr_global);
setup_timer2(TMR_INTERNAL | TMR_DIV_BY_8,10000 );
setup_compare(1,COMPARE_PWM | COMPARE_TIMER2 );
setup_compare(2,COMPARE_PWM | COMPARE_TIMER2 );
setup_adc_ports( sAN9 | sAN10 | sAN11 );
setup_adc(ADC_CLOCK_INTERNAL );
set_pwm_duty(1,1000); // 2ms on status
set_pwm_duty(2,1000); // 2ms on status
rif_int=",";
rif_fin="%c%c",10,13;
output_low(PIN_B8); //common pin for led
output_low(PIN_B6); //led off
output_low(PIN_B7); //led off
do
{
set_adc_channel( 9 );
an_1 = read_adc();
set_adc_channel( 10 );
an_2 = read_adc();
set_adc_channel( 11 );
an_3 = read_adc();
output_high(PIN_B6);
printf("%Lu%c%Lu%c%Lu%c%c",an_1,10,an_2,10,an_3,10,13);
delay_ms(250);
//rec_str="3,";
//cmd=strtok(rec_str,rif_int);
//val=strtok(null,rif_fin);
} while(true);
} |
|
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Mon Jan 26, 2009 9:33 am |
|
|
Move the space after the interrupt (#int_RDA) declaration to the line above
it as shown.
If you do not perform a read of the UART registers the interrupt will not
be cleared. You need to also add a getc() line as illustrated.
Code: | #pin_select U1RX=PIN_B11 //RS-232 RX PIN 22
#use rs232(UART1,baud=57600,parity=N,bits=8,stop=1)
#int_RDA
void RDA_isr(void)
{
xx=getc(); <=== add a line similar to this
output_high(PIN_B7);
}
|
|
|
|
nicotec
Joined: 07 Nov 2008 Posts: 60
|
to try |
Posted: Mon Jan 26, 2009 1:51 pm |
|
|
thanks, I'll try tomorrow morning (Italy) and I'll post here my results; please note also that I need to detect a string as this "55,57" and also need to separate 55 from 57 splitting it in two variable like cmd and val to use in other line; any suggestion will be appreciated.
regards
nicotec |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
Re: to try |
Posted: Mon Jan 26, 2009 2:57 pm |
|
|
nicotec wrote: | thanks, I'll try tomorrow morning (Italy) and I'll post here my results; please note also that I need to detect a string as this "55,57" and also need to separate 55 from 57 splitting it in two variable like cmd and val to use in other line; any suggestion will be appreciated.
regards
nicotec |
Implement a serial ring buffer. Leave it to the mainline code to extract characters from the ring buffer and perform any processing. Check the forum, you will find plenty of examples. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
nicotec
Joined: 07 Nov 2008 Posts: 60
|
near to sove problem |
Posted: Tue Jan 27, 2009 2:06 pm |
|
|
Thanks for your help since I solved some problem; I solved also an hardware problem since I forgotten to connect pin 6 of MAX233 to ground and receiving serial data doesn't work properly.
Now I need to read my string like "55,1" (using interrupt RDA) in a variable and then split 55 and 1 into two variable to process correctly in my main program. I think to use strtok function. What do You think about it?
Thanks in advance and regards.
nicotec |
|
|
nicotec
Joined: 07 Nov 2008 Posts: 60
|
rs232 reading buffer |
Posted: Thu Jan 29, 2009 2:14 pm |
|
|
Hi, I have a question about reading rs232 buffer register, since I need to know type of format of variable
(ex:
char mystring;
gets(mystring); this line is enough to read somethink from rs232 buffer?
Thanks in advance
Regards |
|
|
|
|
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
|