As I enter the ASM code blockk, no LED can be executed after the test for RCIDL and before SLEEP.
Place BSF Portx.x before RCIDL test and SLEEP works.
Place BSF Portx.x after RCIDL test and SLEEP dies not works.
Place BSF Portx.x after BSF BAUDCON, WUE and SLEEP dies not works.
Place BSF Portx.x after BSF INTCON.7 t and SLEEP dies not works.
Before entering the ASM block i can turn on as many LED's as I like and Sleep works as it should.
OK so this is a strange behavure that does not fit any RESET format I can find in the data sheet.
you are still not getting it right evidently.
i can do pretty much anything in the asm block before or after sleep, you really should post your code for any meaningful discussion.
Code:
#CONFIG
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_ON
__config _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_19 & _LVP_OFF
#ENDCONFIG
include "dt_ints-14.bas"
Include "REENTERPBP.bas"
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 7
DEFINE DEBUG_BAUD 9600
DEFINE DEBUG_MODE 1
asm
INT_LIST macro
INT_HANDLER RX_INT , getrx, asm ,yes
INT_HANDLER TMR1_INT , _FLASH, PBP,yes
endm
INT_CREATE
ENDASM
index_in VAR BYTE bank0 ' Pointer - next empty location in buffer
index_out VAR BYTE bank0 ' Pointer - location of oldest character in buffer
errflag VAR BYTE bank0 ' Error flag
UartFlag VAR errflag.0
BufferFlag VAR errflag.1
buffer_size CON 16 ' Sets the size of the ring buffer
buffer VAR BYTE[buffer_size] ' Array variable for holding received characters
BufChar VAR BYTE ' Stores the character retrieved from the buffer
Buffrdy VAR BYTE bank0
buff var byte[16]
inx var byte
led var portc.5
led2 var portc.4
RCSTA = $90 ' Enable serial port & continuous receive
SP1BRGL = 51 ;' 9600 Baud @ 8MHz, 0.16%
SP1BRGH = 0 ;
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
define OSC 8
OSCCON=%01110000 ;8Mhz
ANSELA=$0
ANSELB=$0
ADCON0=$0
PortA=0
PortB=0
PortC=0
TrisA=%00000001
TrisB=%00001001
TrisC=%10001111
Avar var byte
Bvar var byte
Cvar var byte
' rx portc.7
PAUSE 1000
Debug "Start",13 ,13
index_in = 0 ' Initialize ringbuffer variables
index_out = 0
GOSUB error ;CLR AND RESET EUART
T1CON=$31
@ INT_ENABLE RX_INT ; Enable USART RX Interrupts
@ INT_ENABLE TMR1_INT
loopy:
IF errflag Then GOSUB error ' Goto error routine if needed
if Buffrdy then
pie1.4=0
inx=0
while index_in != index_out
GoSub getbuf ' Get a character from buffer
debug bufchar ' Send the character to terminal
buff[inx]= bufchar
inx=inx+1
wend
Buffrdy=0
pie1.4=1
ARRAYREAD buff, 15, loopy,[wait ("sleep")]
gosub SleepMode
endif
GoTo loopy
FLASH:
LED2=!LED2
@ INT_RETURN
SleepMode:
ASM
bcf INTCON ,7
BANKSEL BAUDCON
BTFSS BAUDCON,RCIDL ;Check for High, no receive in progress - tried with and without
GOTO $-1 ;return to previous line
BSF BAUDCON,WUE ;Set to Wake on Rx from Master
BANKSEL 0
BSF PORTC, 5 ;sleep led on
SLEEP
nop
BCF PORTC, 5 ;sleep led off
bsf INTCON ,7
BANKSEL 0
return
ENDASM
' Get a character from the buffer
getbuf: ' Move the next character in buffer to bufchar
intcon = 0 ' Disable interrupts while reading buffer
index_out = index_out + 1 ' Increment index_out pointer
IF index_out => buffer_size Then index_out = 0 ' Reset pointer if outside buffer
bufchar = buffer[index_out] ' Read buffer location(index_out)
INTCON = %11000000 ' Enable interrupts
Return
' Display an error
error: ' Display error message
INTCON = 0 ' Disable interrupts while in the error routine
IF errflag.1 Then ' Determine the error
debug "over run",13,13 '
Else
debug "rx err",13,13
EndIF
PIR1.4=0
errflag = 0 ' Reset the error flag
RCSTA.4=0 'CREN = 0 Disable continuous receive to clear hardware error
RCSTA.4=1 'CREN = 1 Enable continuous receive
INTCON = %11000000 ' Enable interrupts
RETURN ' repeat
Asm
getrx
; Check for hardware overrun error
banksel RCSTA
btfsc RCSTA,OERR ; Check for usart overrun
goto usart_err ; jump to assembly error routine
; Test for buffer overrun
BANKSEL 0
incf _index_in,W ; Increment index_in to W
subwf _index_out,W ; Subtract indexes to test for buffer overrun
btfsc STATUS,Z ; check for zero (index_in = index_out)
goto buffer_err ; jump to error routine if zero
; Increment the index_in pointer and reset it if it's outside the ring buffer
incf _index_in,F ; Increment index_in to index_in
movf _index_in,W ; Move new index_in to W
sublw _buffer_size-1; Subtract index_in from buffer_size-1
btfss STATUS, C ; If index_in => buffer_size
clrf _index_in ; Clear index_in
; Set FSR with the location of the next empty location in buffer
movlw High _buffer ;Store the High byte of buffer to FSR0H
movwf FSR0H
movlw Low _buffer ; Get the Low byte of buffer[0]
addwf _index_in,W ; Add index_in to point to next empty slot
movwf FSR0L ; Store Low byte of pointer in FSR0
; Read and store the character from the USART
BANKSEL RCREG
movf RCREG,W ; Read the received character
movwf INDF0 ; Put the received character in FSR0 location
BANKSEL 0
SUBLW 13
BTFSC STATUS,Z
BSF _Buffrdy ,0
BTFSC PIR1,TXIF ;ANY MORE ?
goto getrx
finished
BANKSEL 0
INT_RETURN
; Error routines
buffer_err ; Jump here on buffer error
bsf _errflag,1 ; Set the buffer flag
usart_err ; Jump here on USART error
bsf _errflag,0 ; Set the USART flag
BANKSEL RCREG
movf RCREG, W ; Trash the received character
goto finished ; Restore state and return to program
EndAsm
Bookmarks