PDA

View Full Version : EUSART Stop Receiving



CocaColaKid
- 26th June 2007, 21:48
I've noticed a problem and can't seem to find an answer. If I run this program everything appears to work great and I get the bytes received back. The problem appears when I trying to send lots of data the program starts to receive and after on or two transmissions is just hangs up and stops responding to data coming in. Anyone have any ideas what might be causing this issue?



DEFINE LOADER_USED 1

DEFINE OSC 16
DEFINE HSER_BAUD 2400
DEFINE HSER_SPBRG 103 ' 19200 Bauds
DEFINE HSER_CLROERR 1 ' Automatically clear over-run errors
DEFINE HSER_RCSTA 90h ' Enable USART receive
DEFINE HSER_TXSTA 20h ' TXSTA=%00100000. TX enable, BRGH=0 for low-speed


x var byte ' General purpose variable
BytesIn var byte[80] ' Serial array - can receive up to 80 bytes
ByteCnt var byte ' Indicates number of bytes in buffer
eom con "~" ' End Of Message marker
rcif var PIR1.5 ' Alias USART received character interrupt flag bit

ByteCnt = 0 ' Zero counter

INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _Receive, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor

INT_ENABLE RX_INT ; enable external (INT) interrupts
ENDASM

Main:
pause 1
goto Main

Receive:
if rCIF then ' If RCIF=1 there's a new character in RCREG
BytesIn[ByteCnt] = RCREG ' Yes. Then store it in array
if BytesIn[ByteCnt] = eom then OutMsg
ByteCnt = ByteCnt + 1 ' Increment array index pointer
endif
goto Receive

OutMsg:
hserout [13,10,dec ByteCnt," Bytes Received",13,10]
hserout [str BytesIn\ByteCnt,13,10]
for x = 0 to ByteCnt ' Clear array bytes 0 to ByteCnt
BytesIn[x] = 0
next x
ByteCnt = 0 ' Reset index pointer back to first element
while RCIF ' Keep reading until RCIF is clear to flush buffer
x = RCREG ' after EOM is received
wend
@ INT_RETURN

Bruce
- 27th June 2007, 19:54
Once in your interrupt handler, interrupts are disabled, so you'll miss new data
that's arriving until you exit & re-enable the interrupt.

I don't think DEFINE HSER_CLROERR 1 is doing any good unless you use
HSERIN, so you would need to clear this manually.

Try reducing the time spent in your interrupt handler. I.E. place;

if BytesIn[ByteCnt] = eom then OutMsg in Main. Remove OutMsg from your int
handler, and let Main take care of displaying messages after eom.

Your interrupt handler should then be fast enough to keep up.


Receive:
if rCIF then ' do you really need this? ' If RCIF=1 there's a new character in RCREG
BytesIn[ByteCnt] = RCREG ' Yes. Then store it in array
ByteCnt = ByteCnt + 1 ' Increment array index pointer
endif
@ INT_ENABLE
It wouldn't hurt to allocate time on the sending device for the PIC to respond
with the complete message before sending more data after the eom marker.