|
|
View previous topic :: View next topic |
Author |
Message |
sindyme
Joined: 05 Aug 2009 Posts: 37
|
My #int_RDA can't work on PIC24F256GB106 |
Posted: Thu Feb 11, 2010 11:59 pm |
|
|
My CCS Verison is 4.104 for "PCDIDE Compiler".
I'm use "PIC24F256GB106" for RS232.
If I no use "#int_RDA" that PIC will be normal work.
But when I use "#int_RDA" function that PIC will unceasing redundant reset.
It will not do main function !
Where is bug at my code ?
These is normal work code.
Code: |
#include <stdio.h>
#include <string.h>
//********************************************************************
#pin_select U1TX=PIN_G6
#pin_select U1RX=PIN_G7
#pin_select U2TX=PIN_D8
#pin_select U2RX=PIN_D9
#use rs232(UART1,baud=115200,parity=N,bits=8,stream=coma)
#use rs232(UART2,baud=115200,parity=N,bits=8,stream=comb)
//********************************************************************
void main()
{
//setup_spi(SPI_MASTER | SPI_MODE_3 |SPI_CLK_DIV_1);
//setup_spi2(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
enable_interrupts(INTR_GLOBAL);
//****************************************************************
for(;;)
{
fprintf(coma,"comb test a ... \r\n");
fprintf(comb,"comb test b ... \r\n");
delay_ms(2000);
}
}
|
If I add #INT_RDA function that PIC will reset again and again
There is bug code.
Code: |
#include <stdio.h>
#include <string.h>
//One rs232 module setting:
char rs_buff[512],check_str[20],str_temp[20];
int16 buff_number,i,j,k,fund_str_point,temp1,temp2;
//Two rs232 module setting:
char rs_buffb[512],check_strb[20],str_tempb[20];
int16 buff_numberb,ib,jb,kb,fund_str_pointb,temp1b,temp2b;
//********************************************************************
#pin_select U1TX=PIN_G6
#pin_select U1RX=PIN_G7
#pin_select U2TX=PIN_D8
#pin_select U2RX=PIN_D9
#use rs232(UART1,baud=115200,parity=N,bits=8,stream=coma)
#use rs232(UART2,baud=115200,parity=N,bits=8,stream=comb)
//********************************************************************
#int_RDA
void RDA_isr(void)
{
//clear_interrupt(INT_RDA2);
disable_interrupts(INT_RDA2);
rs_buff[buff_number]=getc(coma);
if(buff_number<512)
{
buff_number=buff_number+1;
}
else
{
buff_number=0;
}
enable_interrupts(INT_RDA2);
}
//********************************************************************
#int_RDA2
void RDA2_isr(void)
{
//clear_interrupt(INT_RDA);
disable_interrupts(INT_RDA);
rs_buffb[buff_numberb]=getc(comb);
if(buff_numberb<512)
{
buff_numberb=buff_numberb+1;
}
else
{
buff_numberb=0;
}
enable_interrupts(INT_RDA);
}
//RS232 Buff Cls
//********************************************************************
void rs232_buff_cls()
{
for(buff_number=0;buff_number<512;buff_number++)
rs_buff[buff_number]=' ';
buff_number=0; //RS232 Buff Point set to 0
}
//RS232 Buff Clsb
//********************************************************************
void rs232_buff_clsb()
{
for(buff_numberb=0;buff_numberb<512;buff_numberb++)
rs_buffb[buff_numberb]=' ';
buff_numberb=0; //RS232 Buff Point set to 0
}
//Check string
//********************************************************************
void string_buff_check(int str_num_check)
{
temp1=i;
temp2=j;
if(buff_number<str_num_check)
{
fund_str_point=512; //代表無找到或錯誤
}
else
{
for(i=0;i<(buff_number-str_num_check);i++)
{
for(j=0;j<20;j++)
str_temp[j]=' ';
for(j=0;j<str_num_check;j++)
{
str_temp[j]=rs_buff[i+j];
}
//將RS232 BUFF內的字元與輸入字元比較
if(strncmp(str_temp,check_str,str_num_check)==0)
{
fund_str_point=i;
i=buff_number+1;
}
else
{
fund_str_point=512;
}
}
}
i=temp1;
j=temp2;
}
//Check stringb
//********************************************************************
void string_buff_checkb(int str_num_checkb)
{
temp1b=ib;
temp2b=jb;
if(buff_numberb<str_num_checkb)
{
fund_str_pointb=512; //代表無找到或錯誤
}
else
{
for(ib=0;ib<(buff_numberb-str_num_checkb);ib++)
{
for(jb=0;jb<20;jb++)
str_tempb[jb]=' ';
for(jb=0;jb<str_num_checkb;jb++)
{
str_tempb[jb]=rs_buffb[ib+jb];
}
//將RS232 BUFF內的字元與輸入字元比較
if(strncmp(str_tempb,check_strb,str_num_checkb)==0)
{
fund_str_pointb=i;
ib=buff_numberb+1;
}
else
{
fund_str_pointb=512;
}
}
}
ib=temp1b;
jb=temp2b;
}
//********************************************************************
void Module_Initial()
{
RE_Module_Initial:
if(Module_ERR==0)
{
rs232_buff_cls();
fprintf(coma,"AT\r\n"); //check module
delay_ms(200);
strcpy(check_str,"OK");
string_buff_check(2);
if(fund_str_point==512)
{
fprintf(coma,"AT Command Error...\r\n");
GOTO RE_Module_Initial;
}
}
}
void main()
{
//setup_spi(SPI_MASTER | SPI_MODE_3 |SPI_CLK_DIV_1);
//setup_spi2(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
enable_interrupts(INTR_GLOBAL);
//****************************************************************
Module_ERR = 0; GSM_Inlcnt = 0; Msg_ERR = 0; GPRS_ERR = 0;
SISW_ERR = 0;
fprintf(coma,"coma working OK ... \r\n");
fprintf(comb,"comb working OK ... \r\n");
output_high(EEPROM_SELECT); //SPI CS Initial
//****************************************************************
delay_ms(2000);
Module_Initial(); //<--- First do this
for(;;)
{
fprintf(coma,"comb test a ... \r\n");
fprintf(comb,"comb test b ... \r\n");
delay_ms(2000);
}
}
|
There is PIC .h file.
Code: |
#include <24FJ256GB106.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 ICSP1 //ICD uses PGC1/PGD1 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 PR //Primary Oscillator
#FUSES NOCKSFSM //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES IOL1WAY //Allows only one reconfiguration of peripheral pins
#FUSES WPEND_LOW
#FUSES NOWPCFG
#FUSES NOWPDIS
#FUSES WPFP3
#FUSES WPFP4
#FUSES PLL6 //Divide By 12(48MHz oscillator input)
#FUSES DISUVREG
#FUSES WPFP5
#FUSES WPFP6
#FUSES WPFP0
#FUSES WPFP1
#FUSES WPFP2
#FUSES WPFP7
#FUSES WPFP8
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay(clock=22118400)
|
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Feb 12, 2010 2:28 am |
|
|
- Interrupt nesting is disabled by default, you don't need to disable or enable any interrupts in the interrupt function.
- You're writing one byte out of bounds of your rx buffers (rs_buffb[512]).
Apart from these points, I don't see problems with your code. RS232 interrupts are generally working with PIC24 chips and recent PCD versions. |
|
|
Ttelmah Guest
|
|
Posted: Fri Feb 12, 2010 4:00 am |
|
|
Has the problem with the UART numbers being reversed, been fixed?.
If not, then the code would hang.
I really would suggest, getting just _one_ UART working first.
Best Wishes |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Feb 12, 2010 7:20 am |
|
|
Quote: | Has the problem with the UART numbers being reversed, been fixed?. |
Yes, if I remember right. But it's a good idea to check correct SFR usage and PIN_SELECT coding anyway. It has
been partially wrong with PIC24FJxxGB1xx in previous compiler versions and is still wrong for some more exotic
PIC24 types. |
|
|
sindyme
Joined: 05 Aug 2009 Posts: 37
|
|
Posted: Fri Feb 12, 2010 8:34 am |
|
|
FvM wrote: | Quote: | Has the problem with the UART numbers being reversed, been fixed?. |
Yes, if I remember right. But it's a good idea to check correct SFR usage and PIN_SELECT coding anyway. It has
been partially wrong with PIC24FJxxGB1xx in previous compiler versions and is still wrong for some more exotic
PIC24 types. |
I will continue try. This week is chinese new year , I have seven day's holiday.
Next week I will try again ~ |
|
|
|
|
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
|