PDA

View Full Version : MIBAM & USART - PIC resets



vaporized
- 2nd August 2013, 12:26
Hello.
I'm trying to use mr. Taylor's MIBAM and USART communication in a program but can't get anywhere. I guess I'm ruining something with content of some of the registers because approximately 2 seconds after sending data to the PIC it resets.
Please, someone give me a hand with this.


'pbp250a...
'16F887...


DEFINE OSC 20
pause 20
ASM
__CONFIG _CONFIG1, _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_ON & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_ON & _HS_OSC
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
ENDASM


RCSTA = $90
TXSTA = $24
SPBRG = 129
DEFINE HSER_CLROERR 1


RXbff var byte(32)
cnt var byte
n var byte
tmp var byte


OERR var RCSTA.1
CREN var RCSTA.4
RCIF var PIR1.5
RCIE var PIE1.5
'GIE var INTCON.7
'PEIE var INTCON.6


ANSEL = 0
ANSELH = 0

WPUB=0
OPTION_REG.7 = 1


porta = 0
portb = 0
portc = %11000000
portd = 7
porte = 0

trisa = %00010000
trisb = %00000000
trisc = %10000000
trisd = %00000000
trise = %00000000

pause 500



;____[ Interrupt Context save locations ]___________________________________

wsave var byte $20 SYSTEM
wsave1 var byte $A0 SYSTEM
wsave2 var byte $120 SYSTEM
wsave3 var byte $1A0 SYSTEM
ssave var byte BANK0 SYSTEM
psave var byte BANK0 SYSTEM
;_________________________________________________ __________________________


;----[ MIBAM Setup ]--------------------------------------------------------
BAM_COUNT CON 3 ; How many BAM Pins are used?
INCLUDE "MIBAM.pbp" ; Mirror Image BAM module

Red var byte
Green var byte
Blue var byte

ASM
BAM_LIST macro ; Define PIN's to use for BAM
BAM_PIN (PORTB,0, Red) ; and the associated Duty variables
BAM_PIN (PORTB,1, Green)
BAM_PIN (PORTB,2, Blue)
endm
BAM_INIT BAM_LIST ; Initialize the Pins
ENDASM
;_________________________________________________ __________________________



Red = 170: Green = 255: Blue = 120
cnt = 0
'PEIE = 1
'GIE = 1
RCIE = 1



'*****************
MAIN:
'*****************
if OERR then
CREN=0
CREN=1
endif


while RCIF
RXbff[cnt] = RCREG
cnt = cnt + 1
wend

if RXbff[cnt-1] = "~" then
for n = 0 to cnt-1
TXREG = RXbff[n]
pause 3
' hserout [RXbff[n], 32]
next n
TXREG = 13: TXREG = 10
pause 3
' hserout [13, 10]
cnt = 0
endif

goto MAIN
'*****************

Darrel Taylor
- 2nd August 2013, 15:07
You've set the RCIE bit, which enables interrupts for the USART receive path.
But there is no interrupt handler for that interrupt source.

After it receives any data, it will jump to the ISR, which does not handle the interrupt, and does not clear the flag.
So as soon as it exits the ISR, it generates another interrupt because the RCIF flag is still set.

This continues for about 2 seconds until the Watch Dog Timer resets the PIC.

When you are handling the USART receive in the Main loop ... don't set the RCIE bit.

vaporized
- 2nd August 2013, 21:28
OMG, I'm such an idiot! And what is the best, at first I haven't touched the RCIE bit at all, I thought checking the RCIF would be enough. But as I wasn't able to capture any data (god knows what I've messed up then) I've "brilliantly" concluded that the program is not registering data arrival because the RCIF is not being set due to RCIE off. So I switched it on and fell into something which, until your explanation, I didn't understand enough to even try to mess with... Bah, I must be carrying a vapour instead of a brain in my head to poke with things for which I have no adequate apprehension.

Thank you very much, I really appreciate you took the time to help me with this.