|
|
View previous topic :: View next topic |
Author |
Message |
John Morley
Joined: 09 Aug 2004 Posts: 97
|
Problem with Int_RDA |
Posted: Fri Dec 16, 2005 6:34 pm |
|
|
Hi all,
I'm experiencing a strange problem getting the serial interrupt to work on a 16F628 using compiler version 3.162. I know my hardware is OK because I can do this:
Code: |
Main()
{
char c;
while(1)
{
c=fgetc(Console);
fputc(c,Console);
} // while
}
|
All the characters I type on Hyperterminal get echoed right back correctly. However, when I try to use an interrupt to do basically the same thing it doesn't work
Here is a small test program:
Code: |
//-----< Include Files, setup fuses >-----
#include <16f628.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
//-----< Compiler use statements >-----
// Tell compiler clock speed is 20.00 MHZ Crystal
#use delay(clock=20000000)
//-----< General Program Defines >-----
#define Console_Out PIN_A4 // Software RS232 Output to Console Terminal (requires MAX232)
#define Console_In PIN_B1 // Hardware RS232 Input from Console Terminal (requires MAX232)
//-----< Serial Port Definitions >-----
#use rs232(baud=9600, xmit=Console_Out, rcv=Console_In, ERRORS, STREAM=Console)
//-----< Get a RS232 command packet >-----
// Note: This routine is interrupt driven. RS232 input takes priority
// over every other operation in the system.
#int_rda // Interrupt driven RS232 routine
void rs232_isr(void)
{
char temp; // local data storage
temp = fgetc(Console); // get rx data
fputc(temp, Console);
}
Main()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
fprintf(Console,"\n\rHere at the start\n\r");
while(1)
{
} // while
} // end Main
|
When I run this code I never see any characters echoed back. I can see the data arrive just fine at Pin B1 on a scope, but the interrupt doesn't fire!
Any thoughts?
Thanks!
John _________________ John Morley |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 16, 2005 6:54 pm |
|
|
You can't split the hardware UART pins. It's either all hardware or
all software. If you make one pin of the hardware UART become a
software UART, then both pins will be a soft UART. This is a limitation
of the PIC hardware. INT_RDA only works with the hardware UART.
To get a hardware UART for the 16F628, you need to use these pins:
use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS, STREAM=Console) |
|
|
John Morley
Joined: 09 Aug 2004 Posts: 97
|
|
Posted: Fri Dec 16, 2005 9:19 pm |
|
|
PCM,
Thanks for catching that. I'm not sure if it solves my problem, however, as I was never using a serial out to begin with, but added it when I has trouble with the serial interrupt. I'll make the serial output a separate stream for the purposes of my testing and report back.
Thanks Again!
John _________________ John Morley |
|
|
John Morley
Joined: 09 Aug 2004 Posts: 97
|
|
Posted: Mon Dec 19, 2005 8:50 am |
|
|
Hi All,
I made a change to my test program this morning to separate the serial input and output onto two distinct streams, but I still can't get the serial interrupt to work at all. Again, compiler is version 3.162.
Code: |
//-----< Include Files, setup fuses >-----
#include <16f628.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
//-----< Compiler use statements >-----
// Tell compiler clock speed is 20.00 MHZ Crystal
#use delay(clock=20000000)
//-----< General Program Defines >-----
#define Console_Out PIN_A4 // Software RS232 Output to Console Terminal (requires MAX232)
#define Console_In PIN_B1 // Hardware RS232 Input from Console Terminal (requires MAX232)
#define Test_Output PIN_A1 //Pin #18
//-----< Serial Port Definitions >-----
#use rs232(baud=9600, rcv=Console_In, ERRORS, STREAM=Console1)
#use rs232(baud=9600, xmit=Console_Out, STREAM=Console2)
//-----< Get a RS232 command packet >-----
// Note: This routine is interrupt driven. RS232 input takes priority
// over every other operation in the system.
#int_rda // Interrupt driven RS232 routine
void rs232_isr(void)
{
char temp; // local data storage
temp = fgetc(Console1); // get rx data
fputc(temp, Console2);
}
Main()
{
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
fprintf(Console2,"\n\rHere at the start\n\r");
while(1)
{
} // while
} // end Main
|
Again, I know my hardware is OK because I can put the fgetc and the fputc in Main, and all characters are echoed just fine. But for some reason it won't work using the interrupt
Thanks!
John _________________ John Morley |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 19, 2005 2:08 pm |
|
|
Let me be more explicit.
You cannot define half of a hardware serial port with a #use rs232()
statement. If you try to do so, the compiler generates a software UART.
i.e., the following statement in your program will make a soft UART:
Code: | #use rs232(baud=9600, rcv=Console_In, ERRORS, STREAM=Console1)
or more plainly:
#use rs232(baud=9600, rcv=PIN_B1) |
To get a hardware UART, you must put both hardware UART pins
in the #use rs232() statement. Example for 16F628:
Code: | #use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)
|
Also, the ERRORS directive only works with the hardware UART.
If you include it with a soft UART, the compiler will ignore it. |
|
|
John Morley
Joined: 09 Aug 2004 Posts: 97
|
|
Posted: Mon Dec 19, 2005 8:59 pm |
|
|
PCM,
Ugh, I've got it now ! Thanks for taking another swing at this one, I really appreciate it! And, yes, it's working!!
Thanks!
John _________________ John Morley |
|
|
|
|
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
|