PDA

View Full Version : Serial communication only once?



Ziko87
- 10th September 2011, 09:39
Hi,

I wrote the following code:



Main:
HIGH LED_RED
LOW LED_GREEN
pause 500

;Common setup
SPBRG = 129 ;Baud rate 9600
TXSTA.2 = 1 ;BRGH for hight speed
TXSTA.4 = 0 ;USART coomunication
RCSTA.7 = 1 ;Serial enable
;Tx setup
PIE1.4 = 0 ;
TXSTA.6 = 0 ;8 bit
;Rx setup
PIE1.5 = 1
RCSTA.6 = 0
RCSTA.4 = 1
RCSTA.2 = 0
RCSTA.1 = 0

HIGH LED_GREEN
LOW LED_RED
Ever:
;BUTTON switch, 1, 0, 100, button_count, 1, Rx_command
Hserout ["I wait"]
hserin [WAIT("MR")]
HIGH LED_RED
PAUSE 500
low LED_RED
GOTO Ever


The first time posting on the serial "MR,00,0000,CR" works fine, but then the second time does not work anymore. Advise anyone know any solution?

mister_e
- 10th September 2011, 09:52
add

DEFINE HSER_CLROERR 1at the top of your code

mackrackit
- 10th September 2011, 09:55
Put this in the "Ever" loop
RCSTA.4 = 0 : RCSTA.4 = 1

mister_e
- 10th September 2011, 09:59
This is somehow what the define will do, except it will test if there's any error, if so it will clear them

from the .LIB

ifdef HSER_CLROERR
btfsc RCSTA, OERR ; Check for overflow error
bcf RCSTA, CREN ; Toggle continuous receive to clear error
bsf RCSTA, CREN
endif