CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

receiving problems with uart interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bbld



Joined: 14 Dec 2011
Posts: 8

View user's profile Send private message

receiving problems with uart interrupt
PostPosted: Wed Dec 14, 2011 10:43 am     Reply with quote

hi everyone (i'm sorry if my english's not good enough)
i have a project with Sim300cz,
i want to receive string from sim300cz to MCU and then show it on my PC(through hyperterminal).
and hyperterminal show nothing.
here my code,any ideas?
please help me.
i use pic18f97j60
and ccs ver 4.105
Code:

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,stream=SIM300)
#use rs232(baud=9600,xmit=pin_g1,rcv=pin_g2,stream=HOSTPC)
char *Data1 ,*Data2,L1[41],L2[41],L3[41],L4[41];
int i;
#define TX1   PIN_C6
#define RX1   PIN_C7
//-------CH2-------- (For USE PC interfacce)
#define TX2   PIN_G1
#define RX2   PIN_G2
 #INT_RDA
 void IntRDA_isr(void)
{
   #use rs232(baud = 9600, xmit = TX1, rcv = RX1)
   data1=getc();  //data1 is pointer
   #use rs232(baud = 9600, xmit = TX2, rcv = RX2)
   putc(data1);

   if(data1 != 13){    //CR : Carry return
        if(data1 != 10){   //LF : Line Feed
           L1[cn] = data1;   //initial cn=0
                   cn++;
              if(cn >= 40 )cn = 0;
        }
        else{
            cn = 0;
             Clr_msgL4();sprintf(L4,L3);
             Clr_msgL3();sprintf(L3,L2);
             Clr_msgL2();sprintf(L2,L1);
             Clr_msgL1();
         
   //L1
   for(i=0;i<40;i++){fprintf(HOSTPC,">L1[%d]=%c\n\r"i,L1[i]);delay_ms(10);}
   fprintf(HOSTPC,"\n\r");
   
   //L2
   for(i=0;i<40;i++){fprintf(HOSTPC,">L2[%d]=%c\n\r"i,L2[i]);delay_ms(10);}
   fprintf(HOSTPC,"\n\r");
   
   //L3
   for(i=0;i<40;i++){fprintf(HOSTPC,">L3[%d]=%c\n\r"i,L3[i]);delay_ms(10);}
   fprintf(HOSTPC,"\n\r");
   
   //L4
   for(i=0;i<40;i++){fprintf(HOSTPC,">L4[%d]=%c\n\r"i,L4[i]);delay_ms(10);}
   fprintf(HOSTPC,"\n\r");
   
        }     
   }
}
bbld



Joined: 14 Dec 2011
Posts: 8

View user's profile Send private message

PostPosted: Wed Dec 14, 2011 10:49 am     Reply with quote

I can:
+send data:MCU->PC;PC->sim300cz;MCU->sim300cz
+receive data:MCU->PC;Sim300cz->PC
I think i have problem with receive data from uart interrupt.
It seems to receive nothing.
Any helps?
How can i receive data from uart interrupts in my ccs?
temtronic



Joined: 01 Jul 2010
Posts: 9228
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Dec 14, 2011 10:59 am     Reply with quote

some quick comments...

1) always add 'errors' to the use rs232(...) options when using hardware UARTs

2) the USE RS232(...) lines should be outside the ISR, in the 'main' code, in the 'setup' section

3)ISR routines MUST be SHORT and FAST. Those sprintf(...) lines must be in MAIN NOT the ISR.Also get rid of the clr_msg.. functions as well.Have the ISR set 'flags' that the code in MAIN deals with.

4) Why have the delay_ms(10) in the printf(..) code ? It sohouldn't be necessary.
bbld



Joined: 14 Dec 2011
Posts: 8

View user's profile Send private message

thanks for your help temtronic
PostPosted: Wed Dec 14, 2011 11:29 am     Reply with quote

thanks for your help.but when i try with simple code.just send data from my pc to mcu and back to pc through interrupts.
data from mcu send to pc ok
but serial interrupt doesn't work anymore.pc shows nothing.
i think i got a promblem with function getc or something like this.
so you have any ideas?
thanks
Code:

#use delay(clock = FREQ_OSC)
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,errors)

#int_rda
void rda_isr(void)
{
char c;
c = getc();
putc(c);//send to pc to test interrupt receives data,but show nothing
}

//================================
void main()
{
delay_ms(2000);
printf("hello world\n\n");//show on hyperterminal ok

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

while(1);
}

Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Thu Dec 15, 2011 3:29 am     Reply with quote

OK.
There is a fault with the fuses in your compiler version (and several afterwards), that enables the extended CPU mode, even if you select the fuses to not enable this mode. Makes a lot of code not work properly....

I manually override the first five fuses, with:

#ROM 0x300000 = {0xF4A0}

Which is the pattern for:

NOWDT STRVEN NOXINST, and code protect off, to make the code work

Try adding this to your code after your fuses, and see if it starts working.

Best Wishes
bbld



Joined: 14 Dec 2011
Posts: 8

View user's profile Send private message

thanks for your help,mr.Ttelmah
PostPosted: Thu Dec 15, 2011 5:29 am     Reply with quote

i will try it.
thanks for your support.
i''m very appreciate that.
bbld



Joined: 14 Dec 2011
Posts: 8

View user's profile Send private message

hi mr.Ttelmah
PostPosted: Thu Dec 15, 2011 9:32 am     Reply with quote

I had tried to add fuses with your suggestion, but not effect.
I can send data to pc, but i cannot use the uart interrupt. Please help me.
I use pic 18f97j60.
So this's exact my code:
Code:

#include <stdlib.h>
#include <stdio.h>
//#ROM 0x300000 = {0xF4A0}//with it i had warning code is lager than device
#use delay(clock=25000000)
#fuses HS                     // Oscillator mode HS
#fuses NOWDT
//#fuses NOLVP         // my ccs 4.105 not compile this code,it made error
#fuses NOPROTECT,NOXINST

#use fast_io(G)
char c;
#define TX   PIN_G1
#define RX  PIN_G2
#use rs232(baud=9600,xmit=pin_g1,rcv=pin_g2,errors)

#int_rda
void rda_isr(void)
{
char c;
c = getc();
putc(13);
putc(13);
printf("test ok");
putc(c);//send to pc to test interrupt receives data,but show nothing
}

//================================
void main()
{
set_Tris_g(0x04);
delay_ms(2000);
printf("hello world\n\r");//show on hyperterminal ok

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

while(1);
}

best regards
temtronic



Joined: 01 Jul 2010
Posts: 9228
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 15, 2011 10:03 am     Reply with quote

while I don't have that PIC a couple of comments...

1) put enables in main BEFORE the 'forever loop' as shown below..
Code:

void main()

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);


{
set_Tris_g(0x04);
delay_ms(2000);
printf("hello world\n\r");//show on hyperterminal ok


while(1);
}
 

2) get rid of the set_tris(...); code
Let the compiler do it's job and set what is required ,when.If you make an error , odds are the program 'will not work'.

3) disable any peripheral associated with your xmt/rcv pins.

4) check the listing to be sure the compiler has selected the correct serial pins.

5) get rid of the #includes as you're not using anything from them...that I know of...

6) get rid of the fast_io()...Again let the compiler do all the real work!

7) use the CODE button when posting your code, it makes life a LOT easier for all of us in trying to help you.

8) there may be a 'default' for the RS232 stuff, check the PIC.H file to see ?
bbld



Joined: 14 Dec 2011
Posts: 8

View user's profile Send private message

thanks for your help mr.temtronic
PostPosted: Thu Dec 15, 2011 10:57 am     Reply with quote

i will try it.
thanks for your helps mr.temtronic.



best regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Thu Dec 15, 2011 1:06 pm     Reply with quote

Whoa a sec.
Your original 'small example', had the pins in use as C6 and C7. _These are the only pins you can use to get an INT on INT_RDA_.
Your new code uses G1, and G2.

You _must_ set the clock, and fuses _before_ including things like STDIO.
However your code does not use either of the include files you are loading...
You should not get a warning about the code being larger than the device - the reason you are getting this is as posted, the device has not been defined at this point. It _must_ be the first thing done.
Your interrupt _must not_ take longer than one character time to execute. Printing one character is OK, more is not.
The following, compiles, and runs:
Code:

#include <18F97J60.h>
#device adc=8
#FUSES NOWDT, HS, NODEBUG, STVREN, NOPROTECT, NOFCMEN, NOIESO, PRIMARY, ECCPE, NOETHLED, NOWAIT, BW16, EASHFT, NOXINST, MCU
#use delay(clock=25000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
#ROM 0x300000 = {0xF4A0}

#int_rda
void rda_isr(void) {
   char c;
   c = getc();
   putc(c);
}

void main(void) {

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_spi2(FALSE);
   setup_wdt(WDT_OFF);
   delay_ms(2000);
   printf("hello world\n\n");//show on hyperterminal ok

   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   do {
      delay_us(100);
   } while(TRUE);
}


G1, and G2, are the _second_ UART, and will generate INT_RDA2, not INT_RDA.

Best Wishes
bbld



Joined: 14 Dec 2011
Posts: 8

View user's profile Send private message

PostPosted: Thu Dec 15, 2011 11:03 pm     Reply with quote

Ttelmah wrote:

Code:

#include <18F97J60.h>
#device adc=8
#FUSES NOWDT, HS, NODEBUG, STVREN, NOPROTECT, NOFCMEN, NOIESO, PRIMARY, ECCPE, NOETHLED, NOWAIT, BW16, EASHFT, NOXINST, MCU
#use delay(clock=25000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
#ROM 0x300000 = {0xF4A0}

#int_rda
void rda_isr(void) {
   char c;
   c = getc();
   putc(c);
}

void main(void) {

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_spi2(FALSE);
   setup_wdt(WDT_OFF);
   delay_ms(2000);
   printf("hello world\n\n");//show on hyperterminal ok

   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   do {
      delay_us(100);
   } while(TRUE);
}


G1, and G2, are the _second_ UART, and will generate INT_RDA2, not INT_RDA.

Best Wishes

wow,i'm very appreciate your help mr.Ttelmah,it works.
thank you very much.
bbld



Joined: 14 Dec 2011
Posts: 8

View user's profile Send private message

PostPosted: Thu Dec 15, 2011 11:57 pm     Reply with quote

Code:

#include <18F97J60.h>
#device adc=8
#FUSES NOWDT, HS, NODEBUG, STVREN, NOPROTECT, NOFCMEN, NOIESO, PRIMARY, ECCPE, NOETHLED, NOWAIT, BW16, EASHFT, NOXINST, MCU
#use delay(clock=25000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors)
#ROM 0x300000 = {0xF4A0}

your header code is really helpful for me.
thanks again.

best regards
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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