
Originally Posted by
Bruce
By just monitoring flag bits and doing a little house-keeping, you have tons of time to do other things while the hardware UART buffers inbound data for you...
Hello there,
I've been spending some hours on searching information about using HSERIN with its interrupt, RCIF (PIR1.5), and found an interresting info in one of Bruce's posts. It wasn't about the interrupt but he explained and other way around very clearly.
My project is about a 3G monitoring system and receiving SMS messages is crucial (= it is crucial not to miss any incoming SMS).
Why do I search for unsing interrupts? Because, IMO, it's the only way to make sure I will not miss any incoming SMS.
Am I right or not, I don't know and maybe one of you can tell. But in the doubt, I'd like to give the best chances to my program not to oversee any SMS.
Bruce states that there are tons of time to do whatever you need but in my case, where among others I'm controlling four latching relays, setting them and checking their states takes at least 0.5 seconds added to the rest.
I never had the case up to now but I imagine I could receive to SMS within 0.5 seconds (but, as said, I'm not sure).
Anyway, I have posted here under just a piece of my full code where the principle of the RX EUSART interrupt should be tested. Unfortunately, it doesn't work and I can't find why.
Code:
' ====== FUSES 16F690 =============================================================================
#CONFIG
__config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
#ENDCONFIG
@ ERRORLEVEL -306
' ====== REGISTERS =================================================================================
OSCCON = %01110000 ' Internal RC set to 8Mhz - Register not to be used with XTal
OPTION_REG = %10000000 ' PORT A&B Pull-Ups (look WPUA & WPUB)
ADCON0 = %00000000 ' A/D Module
ANSEL = %00000000 ' Select analog inputs Channels 0 to 7
ANSELH = %00000000 ' Select analog inputs Channels 8 to 11
' ====== EUSART SETTINGS ==========================================================================
' Interrupts registers
PIE1.5 = 1 ' Enable interrupt on EUSART
INTCON.7 = 1 ' PEIE peripheral interrupt
INTCON.6 = 1 ' GIE global interrupt
' Hardware EUSART registers (RX = PORTB.5, TX = PORTB.7)
RCSTA = %10010000 ' Enable serial port & continuous receive
TXSTA = %00100000 ' Enable transmit, BRGH = 0
SPBRG = 12 ' 9600 Baud @ 8MHz, 0.16%
' ====== DEFINES ==================================================================================
Define OSC 8
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE NO_CLRWDT 1 ' Forces manual use of CLRWDT
' ====== VARIABLES ================================================================================
LED1 VAR PORTC.4
LED2 VAR PORTC.5
Counter VAR BYTE ' ...a counter
RxBuffer VAR BYTE(18)' maximum SMS length (in characters)
' ====== PROGRAM ==================================================================================
ON INTERRUPT GOTO INCOMING_SMS
WAITING_LOOP:
TOGGLE LED1
PAUSE 1000
GOTO WAITING_LOOP
MAIN:
' Do whatever needs to be done and go back to waiting loop
LED2 = 1
GOTO WAITING_LOOP
END
' ====== ISR ======================================================================================
DISABLE
INCOMING_SMS:
WHILE PIR1.5
RxBuffer(Counter) = RCREG
Counter = Counter +1
WEND
RESUME MAIN
ENABLE
Bookmarks