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 support@ccsinfo.com

Interrupt on 2 different UARTS in 18F6720 locks CPU

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



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

Interrupt on 2 different UARTS in 18F6720 locks CPU
PostPosted: Mon Mar 08, 2004 1:48 pm     Reply with quote

I have a PIC 18F6720 hooked up with a 6MHz Crystal Oscillator and I am tryint to utilize the two hardware UARTS. I have UART1 hooked up to an RF link, and UART2 hooked up to a MAX232 Serial driver. When I have just the UART2 enabled, I can send and receive just fine. No problem.
When I have this line
Quote:

#use rs232(baud=1000, parity=N, xmit=PIN_C6, rcv=PIN_C7, stream=PORT1, bits=8,errors)// RF Receiver

enabled in the code, the program locks up and the debugger has stopped on this very line.
Since I only need the receive function for the RF link, I have the transmit line unconnected( floating), but it being an output pin I figured it would not matter.
Does anyone have an idea what I am doing wrong here?. Why does the CPU lock up when receiving data on UART2 if UART1 is enabled???

Thanks in Advance

Kasper
MPLAB 6.4, PCWH 3.187, WinXP Pro, ICD2
Code:


#include <18F6720.H>          
#include <string.h>
#fuses HS,NOPROTECT,NOWDT,NOLVP //define fuse settings
#use delay(clock=6000000,RESTART_WDT)   //define system clock
#use rs232(baud=1000, parity=N, xmit=PIN_C6, rcv=PIN_C7, stream=PORT1, bits=8,errors)// RF Receiver

#use rs232(baud=38400, parity=N, xmit=PIN_G1, rcv=PIN_G2, stream=PORT2, bits=8,errors)

#int_rda   // This is the RS232 input from the rf receiver.
void RF_IN_Handler(void) {
// code to receive data....

}


#int_rda2   // input from the MAX232
void rs232_handler(void)   {
// code to receive data....

}


[/quote]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 08, 2004 6:40 pm     Reply with quote

The data sheet says the TRIS must be set this way
for the UARTS to work. Try adding these two lines
at the beginning of main(). See if it helps.

set_tris_c(0xBF); // Set pin C6 as an output
set_tris_g(0xFD); // Set pin G1 as an output
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Tue Mar 09, 2004 9:52 am     Reply with quote

I added the lines and I am afraid it made no difference :(

I have stripped my code down to this now:

Code:

#include <18F6720.H> //chip we are using
#include <string.h>
#fuses HS,NOPROTECT,NOWDT,NOLVP   //define fuse settings
#use delay(clock=6000000,RESTART_WDT)   //define system clock
#use rs232(baud=38400, parity=N, xmit=PIN_G1, rcv=PIN_G2, stream=PORT2, bits=8, errors) //,errors)//RS232/USB/Ethernet
#use rs232(baud=1000,  parity=N, rcv=PIN_C7, bits=8, errors)//,ERRORS RF Receiver

void main(void) {
set_tris_c(0xBF); // Set pin C6 as an output
set_tris_g(0xFD); // Set pin G1 as an output
enable_interrupts(INT_RDA);  // RF Receiver Interrupt
enable_interrupts(INT_RDA2);// RS232/USB/Ethernet Receiver Interrupt.
enable_interrupts(GLOBAL);   //enable global Interrupts
fprintf(PORT2,"\n\rSystem Initialized:\n\r"); // tells me that the port is OK
while(true){
}
}
#int_rda   // This is the RS232 input from the rf receiver.
void RF_IN_Handler(void) {
char Received;
Received=getch();
}

#int_rda2   // This is the RS232 input from the PC   
void rs232_handler(void){
char Received2;
Received2=getch();
fprintf(PORT2,"%c",Received2);
}



The code runs fine up to the point where it receives an input on PORT2, which locks the CPU and leaves the ICD cursor on the line
Quote:

#use rs232(baud=1000, parity=N, rcv=PIN_C7, bits=8, errors)

commenting this line out, the code works fine.

I hope someone can help here, as I am at a loss.

Thanks in advance.

Kasper

MPLAB 6.4, PCWH 3.187, WinXP Pro SP1, ICD2
/*edit: missed bracket */
Ttelmah
Guest







PostPosted: Tue Mar 09, 2004 10:35 am     Reply with quote

Try the experiment of using a 'standard' baud rate (ie, 1200bps). Though you'd instictively expect the code to be able to use any acceptable rate, there may be some 'oddity' about handling exotic rates like this.

Best Wishes
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Tue Mar 09, 2004 10:40 am     Reply with quote

I have tried 1200 and 38400bps and the result is the same :(
thanks for the input though Smile
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Mar 09, 2004 10:51 am     Reply with quote

Kasper wrote:
I added the lines and I am afraid it made no difference :(

I have stripped my code down to this now:

Code:

#include <18F6720.H> //chip we are using
#include <string.h>
#fuses HS,NOPROTECT,NOWDT,NOLVP   //define fuse settings
#use delay(clock=6000000,RESTART_WDT)   //define system clock
#use rs232(baud=38400, parity=N, xmit=PIN_G1, rcv=PIN_G2, stream=PORT2, bits=8, errors) //,errors)//RS232/USB/Ethernet
#use rs232(baud=1000,  parity=N, rcv=PIN_C7, bits=8, errors)//,ERRORS RF Receiver

void main(void) {
set_tris_c(0xBF); // Set pin C6 as an output
set_tris_g(0xFD); // Set pin G1 as an output
enable_interrupts(INT_RDA);  // RF Receiver Interrupt
enable_interrupts(INT_RDA2);// RS232/USB/Ethernet Receiver Interrupt.
enable_interrupts(GLOBAL);   //enable global Interrupts
fprintf(PORT2,"\n\rSystem Initialized:\n\r"); // tells me that the port is OK
while(true){
}
}
#int_rda   // This is the RS232 input from the rf receiver.
void RF_IN_Handler(void) {
char Received;
Received=getch();
}

#int_rda2   // This is the RS232 input from the PC   
void rs232_handler(void){
char Received2;
Received2=getch();
fprintf(PORT2,"%c",Received2);
}



The code runs fine up to the point where it receives an input on PORT2, which locks the CPU and leaves the ICD cursor on the line
Quote:

#use rs232(baud=1000, parity=N, rcv=PIN_C7, bits=8, errors)

commenting this line out, the code works fine.

I hope someone can help here, as I am at a loss.

Thanks in advance.

Kasper

MPLAB 6.4, PCWH 3.187, WinXP Pro SP1, ICD2
/*edit: missed bracket */


Use a stream identifier for both ports.
When using putc() do it with an identifier. putc(PORT2)
When using getc() do it with an identifier. getc(PORT2)

You are trying to read a stream that has not recieved any data when another stream has recieved data. The getc() will hang when this happends.
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Wed Mar 10, 2004 9:26 am     Reply with quote

you are indeed right. I used to have the stream in both #useRS232 statements, but started stripping stuff out as it was not working. The secret here seems to be the fgetc(<portname>) command.

fully working code is :
Code:


#include <18F6720.H> //chip we are using
#include <string.h>
#fuses HS,NOPROTECT,NOWDT,NOLVP   //define fuse settings
#use delay(clock=6000000,RESTART_WDT)   //define system clock
#use rs232(baud=38400, parity=N, xmit=PIN_G1, rcv=PIN_G2, stream=PORT2, bits=8, errors) //,errors)//RS232/USB/Ethernet
#use rs232(baud=1200,  parity=N, xmit=PIN_C6, rcv=PIN_C7, stream=PORT1, bits=8, errors) //,ERRORS RF Receiver

void RF_IN_Handler(void);
void rs232_handler(void);


void main(void) {
char Received;
char Received2;
int rxflag=0;
set_tris_c(0xBF); // Set pin C6 as an output
set_tris_g(0xFD); // Set pin G1 as an output
   enable_interrupts(INT_RDA);   // RF Receiver Interrupt
   enable_interrupts(INT_RDA2);// RS232/USB/Ethernet Receiver Interrupt. Will crash the program if left floating.
   enable_interrupts(GLOBAL);            //enable global Interrupts
fprintf(PORT2,"\n\rSystem Initialized:\n\r"); // tells me that the port is OK

while(true){

   } // end while
}// end main


#int_rda   // This is the RS232 input from the rf receiver.
void RF_IN_Handler(void) {
char Received;
Received=fgetc(PORT1);
fprintf(PORT2,"%X",Received);
}

#int_rda2   // This is the RS232 input from the PC   
void rs232_handler(void){
char Received2;
Received2=fgetc(PORT2);
fprintf(PORT2,"%c",Received2);
}




Thanks so much for your help. Smile
Ttelmah
Guest







PostPosted: Wed Mar 10, 2004 10:46 am     Reply with quote

Brilliantly obvious 'in the end', but like most things, not untill it has been spotted!... Smile
The key to what is happening, is that getc/putc, without a stream identifier on a stream based system, default to the 'STDIN' stream, and in the second UART handler, this is not the stream that has received the character.

Best Wishes
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