PDA

View Full Version : hserin buffer



aarothepharo
- 15th January 2013, 19:47
Why only a 2 byte hserin buffer? I'm communicating with MIDI (baud 31250) and I'm not seeing any way to check the hserin fast enough to prevent overflow. It over flows when I get a big packet of straight bytes.

Any tips or tricks?

pedja089
- 15th January 2013, 20:33
http://www.darreltaylor.com/DT_INTS-14/intro.html

aarothepharo
- 15th January 2013, 20:56
I read what you posted in the link. I saw the UART recieve interupt but I'm not sure what an interupt is and how it will help me.

pedja089
- 15th January 2013, 21:04
eg
http://www.picbasic.co.uk/forum/showthread.php?t=11320
Then just put received chars in array

Get_char:
hserin 100,noreceived,[mybyte] 'Get byte
MyArray[Index]=mybyte
Index=Index+1
noreceived: 'or if timeout return
@ INT_RETURN

aarothepharo
- 15th January 2013, 21:26
Pedja089 ... Can you explain in more detail. What i think im reading is this code sets up the hserin to continously read into an array and the program simply needs to check that array?

pedja089
- 15th January 2013, 22:19
When byte is received, PIC jump to Get_char, and get one char, and put it in array. Then PIC goes to do what it was doing before interrupt...

Ioannis
- 17th January 2013, 09:20
What pedja089 posted on #4 is a Interrupt Service Routine (ISR) that is part of a bigger program.

Interrupts might be a difficult subject for the novice, so you have to break your project in small parts and test each part, ensuring you understand the steps you take.

Darrel Taylor has put up this extremely helpful packet for 16 or 18 series PIC controllers but to understand how to do it you have to read a little.

Example (untested):

1. setup the ISR for the serial receive:



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


Whenever you are ready to receive characters place this command

@ INT_ENABLE RX_INT

Your ISR could be the above posted:



Get_char:
hserin 100,noreceived,[mybyte] 'Get byte
MyArray[Index]=mybyte
Index=Index+1
If index>max_array-1 then
index=0
flag_endarray_reached=1
EndIf
noreceived: 'or if timeout return
@ INT_RETURN


Now every time there is a character available it will be put in the array mybyte untill the end is reached.
Then it will wrap arround and a flag will be set so you know that the array was filled up.

Don't forget to include the appropriate files of the DT-INTS for your chip used.

HTH,
Ioannis

Haman03
- 6th May 2013, 04:22
Hserin buffer 16F87x serires input and output buffers are each 47 bytes.

Ioannis
- 6th May 2013, 10:27
If you mean the hardware buffer, then NO. It is only 2 bytes deep.

Ioannis