actually my code is something like this
Code:
Include "Modedefs.Bas"
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25
DEFINE HSER_CLROERR 1
define OSC 4
' Set LCD Data port
DEFINE LCD_DREG PORTD
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 0
' Set LCD Register Select port
DEFINE LCD_RSREG PORTC
' Set LCD Register Select bit
DEFINE LCD_RSBIT 0
' Set LCD Enable port
DEFINE LCD_EREG PORTC
' Set LCD Enable bit
DEFINE LCD_EBIT 1
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 8
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50
SSPEN VAR SSPCON1.5 'SSP Enable bit
CKP VAR SSPCON1.4 'Clock Polarity Select
SMP VAR SSPSTAT.7 'Data input sample phase
CKE VAR SSPSTAT.6 'Clock Edge Select bit
SSPIF VAR PIR1.3 'SPI interrupt flag
OERR var RCSTA.1
CREN var RCSTA.4
RCIF VAR PIR1.5
RCIE var PIE1.5
i VAR BYTE
j var byte
as var byte[5]
com VAR byte[2]
sen var byte[6]
teds1 var byte[10]
teds2 var byte[10]
teds3 var byte[10]
op1 var byte
teds_out var byte[25]
sen0 var byte[10]
sen_all var byte[20]
a var byte[10]
DUM VAR BYTE
TRISC = %10010000 'set PORTC I/O
INTCON=%11000000
PIE1.5=1
SSPEN = 1 'enable SPI pins
CKP = 0 'clock idle low
CKE = 0 'transmit on idle to active transition
SSPIF = 0 'clear buffer full status
SMP = 0 'sample in middle of data
SSPCON1.0 = 0
SSPCON1.1 = 0
SSPCON1.2 = 0
SSPCON1.3 = 0
main:
RCIE=1
pause 100
if RCIF=1 then in
hserout["initialized....",13,10]
pause 10
goto main
in:
hserin[wait("x"),str com\2]
pause 50
hserout["you entered",str com\3,13,10]
pause 100
goto loop
loop:
SSPEN=1
pause 100
for j=0 to 10
high portB.0
pause 25
low portB.0
pause 25
GoSub getdata 'initiate conversion and receive data
LCDOut $fe, 1, STR a\5, DEC a[5] 'display received string
Pause 100
hserout [dec a[4]," ",dec a[5]," ",dec a[6],13,10]
pause 100
next j
pause 100
goto check
getdata:
SSPBUF = "?" 'send ? to start conversion
GoSub letclear 'wait for buffer to clear
IF SSPBUF<>"!" Then getdata 'wait for reply (!)
For i = 0 to 5 'loop for 6 characters
SSPBUF = 0 'write to SSPBUF to start clock
GoSub letclear 'wait for receipt
a[i] = SSPBUF 'store received character in array
Next i 'get next character
Return
letclear:
IF SSPIF = 0 Then letclear 'wait for SPI interupt flag
PauseUs 25 '25uS fudge factor
SSPIF = 0 'reset flag
Return
check:
RCIE=0
WHILE RCIF=1
DUM=RCREG
WEND
CREN=0
pause 25
CREN=1
pause 25
goto main
What basically is a happening that the first HSERIN instrunction which is
HSERIN[wait("x"),str com\2] is executing only once, that is when i turn on the power. the pIC successfuly takes 2 characters as an input after "x" and displays sensors data 10 times which it has acquired from SPI slave through SPI communications. and then when it comes to HSERIN[wait("x"),str com\2] again, it doesnt execute at all, and the PIC seems to be halted.
One observation that i got is this that when i donot use SPI in the above program, im able to use HSERIn again and again. So i think that the problem is somewhere in using SPI. PLease help me dear
Bookmarks