View previous topic :: View next topic |
Author |
Message |
starfire151
Joined: 01 Apr 2007 Posts: 195
|
serial interrupt on PIC16F1574 not working |
Posted: Thu Feb 25, 2021 11:43 am |
|
|
Windows 10
PCWHD V5.071
I'm trying to get the serial interrupt service routine to work on a PIC16F1574 but there's not response. I use this same method with the PIC12LF1572 and it works fine. I've used this same method with multiple other chips and it works fine for them, too. Just not the PIC16F1574.
Code: |
#include <16F1574.h>
#device adc=10
#fuses NODEBUG // No Debug mode for ICD
#fuses NOWDT
#fuses INTRC_IO // internal RC osc with no clkout
#fuses NOPROTECT
#fuses MCLR
#fuses PUT
#fuses NOBROWNOUT
#use delay(internal=16M)
#use rs232(baud=38400, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8)
#define PA_DEF 0b11111111
#define PA_TRIS 0b11001111
#define PC_DEF 0b11111111
#define PC_TRIS 0b11100111
int1 sFlag; // serial input char seen
char sCh; // serial character received
// ---- serial port input ISR ----
#int_RDA
void serialISR(void)
{
sCh = getc();
sFlag = TRUE; // command ready for background execution
}
void main(void)
{
set_tris_a(PA_TRIS);
set_tris_c(PC_TRIS);
set_rtcc(0);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_256);
output_a(PA_DEF);
output_c(PC_DEF);
sFlag = FALSE;
clear_interrupt(INT_RDA);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
delay_ms(500);
printf("startup\r\n");
while(TRUE)
{
if(sFlag) // if serial input seen
{
printf("character %c was seen\r\n", sCh);
sFlag = FALSE;
}
}
}
|
Is there something special about the serial port with this specific chip?
Thanks. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Thu Feb 25, 2021 1:18 pm |
|
|
You need to set it up with PPS.
On any chip where the serial pins support PPS, the way to set it up
is to use #PIN_SELECT, and refer directly to the UART number in #USE
RS232.
Look at the sticky at the top of the forum showing how to do this.
Unless you do this, the default is to implement a software UART, which then
implies no INT_RDA.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9239 Location: Greensville,Ontario
|
|
Posted: Thu Feb 25, 2021 1:29 pm |
|
|
also...
You should add 'ERRORS' as an option to this line...
#use rs232(baud=38400, parity=N, xmit=PIN_C4, rcv=PIN_C5, bits=8)
It will prevent the PICs HW UART from 'locking up' when more than 2-3 characters are sent to it.
Jay |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Thu Feb 25, 2021 2:27 pm |
|
|
Thanks very much!
My oversight... Works like a charm! |
|
|
|