MIBAM & USART - PIC resets


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2009
    Posts
    19

    Default MIBAM & USART - PIC resets

    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.
    Code:
    '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
    '*****************

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: MIBAM & USART - PIC resets

    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.
    DT

  3. #3
    Join Date
    Sep 2009
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: MIBAM & USART - PIC resets

    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.

Similar Threads

  1. Replies: 7
    Last Post: - 23rd November 2011, 16:22
  2. PIC && WiFi suggestions
    By rdxbam in forum General
    Replies: 22
    Last Post: - 26th July 2011, 17:40
  3. Replies: 6
    Last Post: - 9th January 2011, 15:26
  4. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  5. PIC resets every now and then
    By passion1 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th June 2007, 21:41

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts