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

RS232 interrupt problem on 16F877

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







RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 8:58 am     Reply with quote

Hi All,

I am having a problem with the RS232 interrupt. The PIC transmits to hyperterminal 100\%, however the receive doesn't work at all. The signals at the Rx pin are all present and correct, but the PIC does not go into the service routine. I have looked through the history pages of this forum and found the code below to try. And yes,....nothing, only the start message was received.
I even modified the service routine that it would assert an output to an LED as soon as the interrupt occurs, but nothing so obviously it doesn't happen.....but why?????
I am using the Promate and MPLAB to program the PIC.

Can anyone help

James

#include "16F877.h"
#fuses XT,WDT,PUT,NOLVP,NOPROTECT
#use delay(clock=3686400) // Specify clock frequency
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)


#int_rda
void rda_isr(void);

//---------------------------------------------------

main()
{
printf("Start\n\r");

// Enable the USART receive interrupt.
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

// Wait in this foreground loop forever.
// rda interrupts can occur in the background.

while(1);

}

//----------------------------------------
// This is the rda interrupt service function.
// It reads a character from the USART and transmits it back to the PC

#int_rda
void rda_isr(void)
{
static char c;

// Read char from USART.
c = getc();

// Send char back to the PC.
putc(c);

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 5960
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 9:20 am     Reply with quote

Try it like this.

#fuses XT,NOPROTECT,NOBROWNOUT,NOWDT,NOPUT,NOLVP
#use delay(clock=3686400)
#include "16F877.h"
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,ERRORS,stream=chanA)

int1 GreenLED;

#int_RDA
RDA_isr()
{x= fgetC(chanA);
GreenLED = !GreenLED;
output_bit(PIN_C3,GreenLED);}

void main()
{enable_interrupts(INT_RDA);
enable_interrupts(global);
WHILE(TRUE)}}
___________________________
This message was ported from CCS's old forum
Original Post ID: 5961
nilsener
Guest







Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 9:23 am     Reply with quote

May be the watchdog, you have set WDT in the #fuses statement, donīt forget to restart the watchdog in your while(1); loop. Have a look to SETUP_WDT() and RESTART_WDT.



:=Hi All,
:=
:=I am having a problem with the RS232 interrupt. The PIC transmits to hyperterminal 100\%, however the receive doesn't work at all. The signals at the Rx pin are all present and correct, but the PIC does not go into the service routine. I have looked through the history pages of this forum and found the code below to try. And yes,....nothing, only the start message was received.
:=I even modified the service routine that it would assert an output to an LED as soon as the interrupt occurs, but nothing so obviously it doesn't happen.....but why?????
:=I am using the Promate and MPLAB to program the PIC.
:=
:=Can anyone help
:=
:=James
:=
:=#include "16F877.h"
:=#fuses XT,WDT,PUT,NOLVP,NOPROTECT
:=#use delay(clock=3686400) // Specify clock frequency
:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
:=
:=
:=#int_rda
:=void rda_isr(void);
:=
:=//---------------------------------------------------
:=
:=main()
:={
:=printf("Start\n\r");
:=
:=// Enable the USART receive interrupt.
:=enable_interrupts(INT_RDA);
:=enable_interrupts(GLOBAL);
:=
:=// Wait in this foreground loop forever.
:=// rda interrupts can occur in the background.
:=
:=while(1);
:=
:=}
:=
:=//----------------------------------------
:=// This is the rda interrupt service function.
:=// It reads a character from the USART and transmits it back to the PC
:=
:=#int_rda
:=void rda_isr(void)
:={
:=static char c;
:=
:=// Read char from USART.
:=c = getc();
:=
:=// Send char back to the PC.
:=putc(c);
:=
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 5962
James Quest
Guest







Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 9:48 am     Reply with quote

I set up the fuses so that there was not watchdog. Still no joy I am afraid.

James

:=May be the watchdog, you have set WDT in the #fuses statement, donīt forget to restart the watchdog in your while(1); loop. Have a look to SETUP_WDT() and RESTART_WDT.
:=
:=
:=
:=:=Hi All,
:=:=
:=:=I am having a problem with the RS232 interrupt. The PIC transmits to hyperterminal 100\%, however the receive doesn't work at all. The signals at the Rx pin are all present and correct, but the PIC does not go into the service routine. I have looked through the history pages of this forum and found the code below to try. And yes,....nothing, only the start message was received.
:=:=I even modified the service routine that it would assert an output to an LED as soon as the interrupt occurs, but nothing so obviously it doesn't happen.....but why?????
:=:=I am using the Promate and MPLAB to program the PIC.
:=:=
:=:=Can anyone help
:=:=
:=:=James
:=:=
:=:=#include "16F877.h"
:=:=#fuses XT,WDT,PUT,NOLVP,NOPROTECT
:=:=#use delay(clock=3686400) // Specify clock frequency
:=:=#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
:=:=
:=:=
:=:=#int_rda
:=:=void rda_isr(void);
:=:=
:=:=//---------------------------------------------------
:=:=
:=:=main()
:=:={
:=:=printf("Start\n\r");
:=:=
:=:=// Enable the USART receive interrupt.
:=:=enable_interrupts(INT_RDA);
:=:=enable_interrupts(GLOBAL);
:=:=
:=:=// Wait in this foreground loop forever.
:=:=// rda interrupts can occur in the background.
:=:=
:=:=while(1);
:=:=
:=:=}
:=:=
:=:=//----------------------------------------
:=:=// This is the rda interrupt service function.
:=:=// It reads a character from the USART and transmits it back to the PC
:=:=
:=:=#int_rda
:=:=void rda_isr(void)
:=:={
:=:=static char c;
:=:=
:=:=// Read char from USART.
:=:=c = getc();
:=:=
:=:=// Send char back to the PC.
:=:=putc(c);
:=:=
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 5965
James Quest
Guest







Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 9:51 am     Reply with quote

The compiler did not like the #use rs232 command. the error i received was : USE parameter value is out of range.

if I take away the stream part of the command, it allows it but obviously {x= fgetC(chanA); give an undeclared identifier error.

please can you help/explain.....?

James

:=Try it like this.
:=
:=#fuses XT,NOPROTECT,NOBROWNOUT,NOWDT,NOPUT,NOLVP
:=#use delay(clock=3686400)
:=#include "16F877.h"
:=#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,ERRORS,stream=chanA)
:=
:=int1 GreenLED;
:=
:=#int_RDA
:=RDA_isr()
:= {x= fgetC(chanA);
:= GreenLED = !GreenLED;
:= output_bit(PIN_C3,GreenLED);}
:=
:=void main()
:= {enable_interrupts(INT_RDA);
:= enable_interrupts(global);
:= WHILE(TRUE)}}
___________________________
This message was ported from CCS's old forum
Original Post ID: 5966
Hans Wedemeyer
Guest







Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 10:08 am     Reply with quote

I posted some example code...

<a href="http://www.pic-c.com/forum/general/posts/5938.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/5938.html</a>

Try not to do putc() inside the ISR.

Using getc() is OK but is not needed... see my listing...
___________________________
This message was ported from CCS's old forum
Original Post ID: 5967
James Quest
Guest







Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 10:23 am     Reply with quote

Thanks for that....
I tried the code as shown below, but no response!!!!!
What do you think?

James

#include "16F877.h"
#fuses XT,NOWDT,PUT,NOLVP,NOPROTECT
#use delay(clock=3686400) // Specify clock frequency
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

#byte RXREG = 0X1A
int RxData;
short int DataValid=FALSE;

void InitSystem(void);

//////////////////////////////
// RS232 receive interrupt
#int_RDA
RDA_isr()
{
RxData = RXREG;
DataValid = TRUE;
}

void main()
{
InitSystem();

do{
if( DataValid == TRUE )
{
DataValid = FALSE;
switch(RxData)
{
case 'X':
putchar('*');
break;
default:
putchar('?');
break;
}
}

}while(1); // forever loop

}


void InitSystem(void)
{

#define TRIS_A_INIT 0x09

#define TRIS_B_INIT 0xFF


#define TRIS_C_INIT 0x81


#define TRIS_D_INIT 0x04


#define TRIS_E_INIT 0x07


//initialise the port direction registers

set_tris_a(TRIS_A_INIT);
set_tris_b(TRIS_B_INIT);
set_tris_c(TRIS_C_INIT);
set_tris_d(TRIS_D_INIT);
set_tris_e(TRIS_E_INIT);


setup_counters(RTCC_INTERNAL, WDT_2304MS);


enable_interrupts(INT_RDA);

enable_interrupts(GLOBAL);



return;


}




:=I posted some example code...
:=
:= <a href="http://www.pic-c.com/forum/general/posts/5938.html" TARGET="_blank"> <a href="http://www.pic-c.com/forum/general/posts/5938.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/5938.html</a></a>
:=
:=Try not to do putc() inside the ISR.
:=
:=Using getc() is OK but is not needed... see my listing...
___________________________
This message was ported from CCS's old forum
Original Post ID: 5968
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 10:26 am     Reply with quote

:=Hi All,
:=
:=I am having a problem with the RS232 interrupt. The PIC transmits to hyperterminal 100\%, however the receive doesn't work at all. The signals at the Rx pin are all present and correct, but the PIC does not go into the service routine. I have looked through the history pages of this forum and found the code below to try. And yes,....nothing, only the start message was received.
:=I even modified the service routine that it would assert an output to an LED as soon as the interrupt occurs, but nothing so obviously it doesn't happen.....but why?????
:=I am using the Promate and MPLAB to program the PIC.
-----------------------------------------------------

What's your version of the compiler ?

That looks like my sample code.

I'd suggest that you get it going without interrupts
first. Try something like this:


main()
{

char c;

while(1)
{
if(kbhit())
{
c = getc();
c++;
putc(c);
}
}

}


That should echo the char, incremented by 1.
This should test out the whole communcation setup.

Have to be out of the office all day. HTH.
___________________________
This message was ported from CCS's old forum
Original Post ID: 5969
James Quest
Guest







Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 10:53 am     Reply with quote

Yes, I have tried this before and it works OK.
I am using the PCM compiler ver 2.734

James

:=
:=What's your version of the compiler ?
:=
:=That looks like my sample code.
:=
:=I'd suggest that you get it going without interrupts
:=first. Try something like this:
:=
:=
:=main()
:={
:=
:=char c;
:=
:=while(1)
:= {
:= if(kbhit())
:= {
:= c = getc();
:= c++;
:= putc(c);
:= }
:= }
:=
:=}
:=
:=
:=That should echo the char, incremented by 1.
:=This should test out the whole communcation setup.
:=
:=Have to be out of the office all day. HTH.
___________________________
This message was ported from CCS's old forum
Original Post ID: 5970
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 11:45 am     Reply with quote

:=The compiler did not like the #use rs232 command. the error i received was : USE parameter value is out of range.
:=
:=if I take away the stream part of the command, it allows it but obviously {x= fgetC(chanA); give an undeclared identifier error.
:=
:=please can you help/explain.....?
:=
:=James
:=

Stream parameter is used with later versions of the compiler to direct data to different ports and is not supported by versions prior to 3. This is only an useful when using more than 1 serial port.


Edited for earlier version of the compiler.
This should toggle pin C3 with each incomming byte.

#fuses XT,NOPROTECT,NOBROWNOUT,NOWDT,NOPUT,NOLVP
#use delay(clock=3686400)
#include "16F877.h"
#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

int1 GreenLED;

#int_RDA
RDA_isr()
{x= getC();
GreenLED = !GreenLED;
output_bit(PIN_C3,GreenLED);}

void main()
{enable_interrupts(INT_RDA);
enable_interrupts(global);
WHILE(TRUE)}}
___________________________
This message was ported from CCS's old forum
Original Post ID: 5971
Hans Wedemeyer
Guest







Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 1:19 pm     Reply with quote

I compiled and ran your code, at the moment I have hardware setup for PIC16F876 and 4MHz so all I changed was the Osc.F and Tris Setup ..

This code works as advertised...

Perhaps you should check your hardware. Is the MAX232 (I assume) connected correctly ?
Is the PIC Osc. running at the correct frequency ?
Sometimes if the crystal is of the wrong type it may not run at the fundemental !

This work 100\%

#include "H:\picc\examples\16F876.h"
#fuses XT,NOWDT,PUT,NOLVP,NOPROTECT
#use delay(clock=4000000) // Specify clock frequency
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

void InitSystem(void) ;

#byte RXREG = 0X1A
int RxData=0;
int DataValid=0;

//////////////////////////////
// RS232 receive interrupt
#int_RDA
RDA_isr()
{
RxData = RXREG;
DataValid = 1;
}

void main()
{
InitSystem();
DataValid = 0;

do{
if( DataValid == 1 )
{
DataValid = 0;
switch(RxData)
{
case 'X':
putchar('*');
break;
case 'Q':
puts("Received Q");
break;
default:
putchar('?');
break;
}
}

}while(1); // forever loop

}

void InitSystem(void)
{
#define TRIS_A_INIT 0x09
#define TRIS_B_INIT 0xFF
#define TRIS_C_INIT 0x81
//#define TRIS_D_INIT 0x04
//#define TRIS_E_INIT 0x07
//initialise the port direction registers
set_tris_a(TRIS_A_INIT);
set_tris_b(TRIS_B_INIT);
set_tris_c(TRIS_C_INIT);
//set_tris_d(TRIS_D_INIT);
//set_tris_e(TRIS_E_INIT);

setup_counters(RTCC_INTERNAL, WDT_2304MS);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
return;
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 5974
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: RS232 interrupt problem on 16F877
PostPosted: Wed Jul 31, 2002 8:13 pm     Reply with quote

I cut and pasted the program you posted into a project,
and compiled it with PCM vs. 2.734. The only things
I changed were:
1. Clock freq to 8 MHz.
2. Osc fuse to HS (because of 8 MHz crystal).
3. Removed the WDT fuse.

It ran OK. I used a 16F877-20/P.

I used the Win 3.1 terminal program, running under Win98.
(no hardware handshaking).
___________________________
This message was ported from CCS's old forum
Original Post ID: 5987
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