I cannot point to it, but I am betting there is an interrupt flag that gets set the first go around that you need to clear in code.
I cannot point to it, but I am betting there is an interrupt flag that gets set the first go around that you need to clear in code.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
It may help by adding DEFINE HSER_CLROERR 1 to your USART init section.
ok guys!
so i have studied a few threads here and made the following modifications in the SPI master program. but again the same problem is occuring. In the first iteration, the program runs very fine, but when it comes to hserin the second time, the program halts and no data is hserin in the pic.
plz help me , this is my final year project, and due to this the whole project is getting affected.
Code:'**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 7/5/2008 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** 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: dum=RCREG pause 50 hserout["you entered",dec dum,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 hserout["find",13,10] pause 100 CREN=0 pause 25 WEND goto main
LETS MOVE TOWARDS SOMETHING PRACTICAL---
Seems like you need to follow CREN=0 with CREN=1 to reenable continuous receive
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
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
LETS MOVE TOWARDS SOMETHING PRACTICAL---
shaiqbashir, Where is your interrupt routine? You are setting up the interrupts but only looking at the interrupt input flags. There is no need to setup the global interrupt bits as once again all you are doing is (polling) looking at the input flag bits..
Dave Purola,
N8NTA
ok i will disable global interrupts and will check it. But interrupt is not a problem here. The first time it executes very perfectly, it is the second time that is creating a huge problem. Second time, on hserin statement, the PIC hangs.
kindly help
LETS MOVE TOWARDS SOMETHING PRACTICAL---
Bookmarks