Searching \ for '[PIC]: USART Buffer' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=usart
Search entire site for: 'USART Buffer'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: USART Buffer'
2001\02\01@195424 by Glenn Mitchell

flavicon
face
Hello.  I hope someone can give me some pointers.  I need to buffer 15 bytes
coming into a 16C63A from a peripheral.  Is it possible to buffer incoming
bytes into sequential file registers and then index and read the bytes like
a table?  I have been trying to act on the bytes in real-time but I am
getting odd results.  Time to try something else.  Thanks for your help.

Glenn Mitchell.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\02\01@211014 by Jeff Meyer

flavicon
face
One thing I have done (on the 18C452) is to copy all of the bytes coming in
on the serial port to an area of RAM and then process the data after the
last character of a message (determined by a timeout) has been recieved.  I
did it this way because the number of characters coming in is unknown (from
10 bytes to 212 bytes).  I would also like to see if there is a better way
to do this (I'm sure there is).  The previous project (that this one is
loosely based on) did not do any checksumming, and it just processed the
message byte by byte as it came in.  We wanted this one to be a little more
robust... :)

One system I am working on (not a PIC) has an MFI (Multi Function
Interface) that handles all of the inputs.  It figures out when a complete
message has been received, DMAs it to a RAM buffer (set by registers in the
MFI), and then generates an interrupt to inform the processor that new data
is ready to process.  One benefit of this system is that RAM is not an
issue, so we can have a huge RAM buffer area set up so incoming messages
can be processed at any time during the 1 second cycle without worrying
about cycle slips and so on.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\02\01@214625 by Bob Ammerman

picon face
Check your data sheet for references to INDF and FSR. They provide the
ability to build a table in RAM.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Original Message removed}

2001\02\02@054802 by o-8859-1?Q?K=FCbek_Tony?=

flavicon
face
Try,


http://www.piclist.com/techref/microchip/16f876-hint-tk.htm

( or rather the source page
www.piclist.com/techref/microchip/rs232.htm
)

'Piclist.com for all you pic'n needs' (tm) :)


/Tony

Tony Kübek, Flintab AB            
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
E-mail: spam_OUTtony.kubekTakeThisOuTspamflintab.com
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\02\02@092416 by Sergio Picado

flavicon
face
       In the serial receive subroutine use the  INDF and FSR commands to make an
independent buffer to receive the characters as the characters are coming
in.  If the messages to be received always start with a certain character
(very common in master-slave configurations for example) have your buffer
subroutine only see that character before it begins to fill your buffer up.
You might want to set up a flag pointer to tell you when to check the buffer
(when an EOT character has been sent or when the buffer has been filled to a
certain point) during the body of the program.

       Depending on the number of characters you expect, keep your buffer as small
as possible and keep your routines in the interrupt part of the program as
small aspossible as well.

       Cheers

.


{Original Message removed}

2001\02\02@100735 by Olin Lathrop

face picon face
> Hello.  I hope someone can give me some pointers.  I need to buffer 15
bytes
> coming into a 16C63A from a peripheral.  Is it possible to buffer incoming
> bytes into sequential file registers and then index and read the bytes
like
> a table?

Yup, that's what a buffer is all about.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\02\02@133154 by Glenn Mitchell

flavicon
face
Thanks everyone.  The INDF and FSR commands will do the trick.  The strings
I need to read have start and delimiting characters.  No problem.

Glenn Mitchell.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics



'[PIC]: USART buffer'
2001\03\19@191246 by Edson Brusque
face
flavicon
face
Hello,

   anyone here have implemented a FIFO (First In, First Out) buffer for the
hardware USART of a PIC? I'm using a PIC16F877 and it does have to receive
USART and put it on a buffer for later processing.

   How do I implement it? I think I need two variables and an array, like:

       USART_BUFFER[8];    // for 8 locations
       USART_COUNTER;      // how many locations filled
       USART_POSITION;     // the last position filled

   When I receive a byte, I put it on (USART_POSITION + 1) and increment
USART_COUNTER.
   When USART_COUNTER = 8 , I generate an OVERRUN error.
   When USART_POSITION = 8, I make USART_POSITION = 0;

   This is so I don't have to waste time doing:
       USART_BUFFER[0] = USART_BUFFER[1];
       USART_BUFFER[1] = USART_BUFFER[2];
       USART_BUFFER[2] = USART_BUFFER[3];
       USART_BUFFER[3] = USART_BUFFER[4];
       USART_BUFFER[4] = USART_BUFFER[5];
       USART_BUFFER[5] = USART_BUFFER[6];
       USART_BUFFER[6] = USART_BUFFER[7];

   everytime I pull a byte.

   Is there an smarter way?

   Best regards,

   Brusque

-----------------------------------
Edson Brusque
Research and Development
C.I.Tronics Lighting Designers Ltda
(47) 323-2685  /  (47) 9993-6453
Blumenau  -  SC  -  Brazil
http://www.citronics.com.br
-----------------------------------

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\03\19@192345 by David Huisman

flavicon
face
Hi,

Hope this bit of code might help.

bRF_Timeout = false;
cRF_Time = cTick + 6;

cRX_RF_Byte = RCREG2;              //otherwise, get data byte from
Receive(1) buffer


switch (cRF_Mode)                  //RF RX state machine
      {                                       //must receive PREAMBLEe
followed immediately by SYNC to start reception
         case IDLE         :
                             if(cRX_RF_Byte = PREAMBLE)   //Is current byte
a PREAMBLE (0xAA) byte ?
                             {
                               cRF_Mode = GOT_PREAMBLE; //YES.. then switch
state to look for SYNC byte (0X33)
                             }
                             break;                     //NO... then ignore
and stay in IDLE mode

         case GOT_PREAMBLE :
                             if(cRX_RF_Byte == SYNC)    //is current byte
SYNC ?
                             {
                               cRF_Mode = RECEIVING;    //YES.. change
state to receive mode
                              cRX_RF_Ptr = 0;          //reset RX data
buffer pointer
                             }                          //NO... if another
PREAMBLE then stay in present state
                             else if(cRX_RF_Byte != 0xAA) cRF_Mode = IDLE;
//else reset state back to IDLE
                             break;

         case RECEIVING   :
                             cRX_RF_Buf[cRX_RF_Ptr] = cRX_RF_Byte;
//store byte into RF Receive buffer
                             cRX_RF_Ptr++;                         //point
to next location in buffer
                             if(cRX_RF_Ptr > 9)                    //fixed
length packet has been received
                             {
                               cRF_Mode = IDLE;                    //reset
state machine to IDLE mode
                               bReceived_RF_Packet = true;     //set flag
to indicate packet has arrived
                               break;
                             }
       }      //end of switch routine

The main program loop setes cRX_Mode = IDLE if timeout occurs due to
incomplete packet being receieved.

Regards

David Huisman

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\03\20@041914 by leo.perretti

flavicon
face
Edson,

I have implemented the routine you mention for the 17c44; I think it
could be adapted to the 877 with almost no change. I use it for
receiving chars from the serial port of the computer.

The buffer is 16 bytes long, and starts from 0x20.
recNum is the number of bytes actually stored in the buffer.
recPtr is the pointer to the last received byte.
This is the chunk of code for initializating the FIFO:

......
       clrf recNum     ;set the FIFO to empty
       movlw 0x20              ;set the next byte to the FIFO base
       movwf recPtr
......


Next is the receiving (FIFO in) routine. I adapted it from a multiple
bytes receiving routine; in this case it receives just one byte at a
time. Maybe it could be semplified somehow.
rec1Byte is a routine which receives one byte from the serial port; it
returns with the received byte in tmpReg2, the number of received bytes
in tmpReg1 (this is 1 in this case), and an error code in errCode (0 for
no error; this is also used to complete reception and exit the routine).

recLoop
       call rec1Byte
       movlb 0
       tstfsz errCode
       goto recCompl                   ;an error occurred
       movwf tmpReg2
       movfp recNum,WREG
       incf recNum
       addwf recPtr,0
       bcf WREG,4
       movwf FSR0
       movfp tmpReg2,INDF0
       decfsz tmpReg1
       goto recLoop


Next is the fetching (FIFO out) routine. If the buffer is empty, it
returns with an error code in errCode (0 for no error), else it returns
with the fetched byte in WREG

fetchNextRcCh
       movlb 0
       clrf errCode
       tstfsz recNum
       goto valChar
       movlw eEmptyRecBuf
       movwf errCode
       retlw 0xff
valChar
       movfp recPtr,FSR0
       decf recNum
       incf recPtr
       bcf recPtr,4
       movfp INDF0,WREG
       return


Hope this helps.

Regards
Leonardo Perretti
leo.perrettispamKILLspamprojectpp.it


Edson Brusque wrote:

>    anyone here have implemented a FIFO (First In, First Out) buffer for the
>hardware USART of a PIC? I'm using a PIC16F877 and it does have to receive
>USART and put it on a buffer for later processing.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\03\20@075718 by Olin Lathrop

face picon face
part 1 708 bytes content-type:text/plain; (decoded 7bit)

>     anyone here have implemented a FIFO (First In, First Out) buffer for
the
> hardware USART of a PIC? I'm using a PIC16F877 and it does have to receive
> USART and put it on a buffer for later processing.
>
>     How do I implement it? I think I need two variables and an array,
like:

The attached file contains macros that implement and manipulate FIFOs.  They
are supposed to work on both the 16xxx and 17xxx families.  However, I
sortof remember some changes were made since the last time they were
verified on the 16xxx family.  That's why I haven't added them to my
"standard" macros yet in STD.INS.ASPIC at http://www.embedinc.com/pic.


part 2 8879 bytes content-type:text/plain;
(decoded quoted-printable)

;
;***********************************************************************
;
;   Macro FIFO_DEFINE name size
;
;   Define a first in, first out queue.  The symbol NAME will be defined as
;   the first byte of the queue structure.  Size is the maximum number of
;   data bytes the queue can hold.  The format of a FIFO is:
;
;     name+0  -  number of data bytes currently in the queue
;
;     name+1  -  offset into the queue of where to put the next byte + 1
;
;     name+2  -  offset into the queue of where to get the next byte from + 1
;
;     name+3 thru name+2+size  -  Data buffer.  Sequential bytes are written
;       and read at decreasing addresses until the start of the buffer is
;       reached, in which case the next address wraps back to the end of the
;       buffer.
;
fifo_ofs_n equ   0           ;offset from FIFO label for number of bytes in buffer
fifo_ofs_put equ 1           ;offset from FIFO label for PUT index
fifo_ofs_get equ 2           ;offset from FIFO label for GET index
fifo_ofs_buf equ 3           ;offset from FIFO label for start of buffer

fifo_define macro name, size
name     res     1           ;number of data bytes currently in the queue
        res     1           ;put offset
        res     1           ;get offset
        res     size        ;the data buffer
        endm
;
;***********************************************************************
;
;   Macro FIFO_INIT name
;
;   Initialize the FIFO at NAME.  The register bank must be set for access
;   to the FIFO state.  SIZE is the number of data bytes the FIFO was
;   defined for.
;
fifo_init macro  name
        clrf    name + fifo_ofs_n ;indicate the FIFO is empty
        movlw   1
        movwf   name + fifo_ofs_put ;init PUT index
        movwf   name + fifo_ofs_get ;init GET index
        endm
;
;***********************************************************************
;
;   Macro FIFO_SKIP_EMPTY name
;
;   Skips the next instruction after the macro if the FIFO at NAME is
;   empty.  The register bank must be set for access to the FIFO state.
;
fifo_skip_empty macro name

 if fam_16 || fam_12
        movf    name + fifo_ofs_n ;set Z if FIFO empty
        skip_z
        exitm
   endif

 if fam_17
        tstfsz  name + fifo_ofs_n ;skip if FIFO empty
        exitm
   endif

        error   "Macro FIFO_SKIP_EMPTY not implemented for this processor"
        endm
;
;***********************************************************************
;
;   Macro FIFO_SKIP_NEMPTY name
;
;   Skips the next instruction after the macro if the FIFO at NAME
;   contains at least one data byte.  The register bank must be set for
;   access to the FIFO state.
;
;   W may be trashed.
;
fifo_skip_nempty macro name

 if fam_16 || fam_12
        movf    name + fifo_ofs_n ;set Z if FIFO empty
        skip_nz             ;FIFO not empty ?
        exitm
   endif

 if fam_17
        decf    name + fifo_ofs_n, w ;set borrow flag if FIFO is empty
        skip_nborr          ;FIFO not empty ?
        exitm
   endif

        error   "Macro FIFO_SKIP_NEMPTY not implemented for this processor"
        endm
;
;***********************************************************************
;
;   Macro FIFO_SKIP_FULL name size
;
;   Skips the next instruction after the macro if the FIFO at NAME is
;   completely full.  The register bank must be set for access to the
;   FIFO state.
;
;   W is trashed.
;
fifo_skip_full macro name, size
        movlw   size        ;get max bytes the FIFO can hold
        subwf   name + fifo_ofs_n, w ;compare to number of bytes currently in FIFO
        skip_wle            ;FIFO is completely full ?
        endm
;
;***********************************************************************
;
;   Macro FIFO_SKIP_NFULL name size
;
;   Skips the next instruction after the macro if the FIFO at NAME is
;   not completely full.  The register bank must be set for access to
;   the FIFO state.
;
;   W is trashed.
;
fifo_skip_nfull macro name, size
        movlw   size        ;get max bytes the FIFO can hold
        subwf   name + fifo_ofs_n, w ;compare to number of bytes currently in FIFO
        skip_wgt            ;FIFO is completely full ?
        endm
;
;***********************************************************************
;
;   Macro FIFO_PUT name size data
;
;   Add the byte in DATA as the last byte in the FIFO at NAME.  SIZE must
;   be the maximum number of bytes the FIFO was defined to hold.  The
;   register bank must be set for access to the FIFO and DATA.  Since the
;   FIFO is usually not in global RAM, this means DATA must be either in
;   global RAM or in the same register bank as the FIFO.
;
;   The FIFO may be trashed if it is already full.  This should be checked
;   before this macro is called.
;
;   Note that if the FIFO could be accessed from the interrupt service
;   routine, then interrupts should be temporarily disabled around this
;   macro.
;
;   W is trashed.
;
fifo_put macro name, size, data
;
;   12 and 16 family processors.
;
 if fam_16 || fam_12
        movlw   name + (fifo_ofs_buf - 1) ;get address for buffer index 0
        addwf   name + fifo_ofs_put, w ;make address of where to write this new byte
        movwf   fsr         ;point to where to write the byte
        movf    data, w     ;get the data byte into W
        movwf   indf        ;write the data byte into the buffer

        incf    name + fifo_ofs_n ;indicate one more byte now in the FIFO
        movlw   size        ;get offset for last byte in buffer
        decf    name + fifo_ofs_put ;update buffer index to next byte, set Z on wrap
        skip_nz             ;not just decrement past beginning of buffer ?
        movwf   name + fifo_ofs_put ;wrap back to end of buffer
        exitm
   endif
;
;   17 family processors.
;
 if fam_17
        movlw   name + (fifo_ofs_buf - 1) ;get address for buffer index 0
        addwf   name + fifo_ofs_put, w ;make address of where to write this new byte
        movwf   fsr0        ;point to where to write the byte
        movfp   data, indf0 ;write the data byte into the buffer

        incf    name + fifo_ofs_n ;indicate one more byte now in the FIFO
        movlw   size        ;get offset for last byte in buffer
        dcfsnz  name + fifo_ofs_put ;update buffer index, skip on not wrap
        movwf   name + fifo_ofs_put ;wrap back to end of buffer
        exitm
   endif

        error   "Macro FIFO_PUT not implemented for this processor"
        endm
;
;***********************************************************************
;
;   Macro FIFO_GET name size data
;
;   Get the next byte from the FIFO at NAME into DATA.  SIZE must
;   be the maximum number of bytes the FIFO was defined to hold.  The
;   register bank must be set for access to the FIFO and DATA.  Since the
;   FIFO is usually not in global RAM, this means DATA must be either in
;   global RAM or in the same register bank as the FIFO.
;
;   The FIFO may be trashed if it is already empty.  This should be
;   checked before this macro is called.
;
;   Note that if the FIFO could be accessed from the interrupt service
;   routine, then interrupts should be temporarily disabled around this
;   macro.
;
;   W is trashed.
;
fifo_get macro name, size, data
;
;   12 and 16 family processors.
;
 if fam_16 || fam_12
        movlw   name + (fifo_ofs_buf - 1) ;get address for buffer index 0
        addwf   name + fifo_ofs_get, w ;make address of where to read new byte from
        movwf   fsr         ;point to where to read the byte from
        movf    indf, w     ;get the data byte
        movwf   data        ;pass it back

        decf    name + fifo_ofs_n ;indicate one less byte now in the FIFO
        movlw   size        ;get offset for last byte in buffer
        decf    name + fifo_ofs_get ;update buffer index to next byte, set Z on wrap
        skip_nz             ;not just decrement past beginning of buffer ?
        movwf   name + fifo_ofs_get ;wrap back to end of buffer
        exitm
   endif
;
;   17 family processors.
;
 if fam_17
        movlw   name + (fifo_ofs_buf - 1) ;get address for buffer index 0
        addwf   name + fifo_ofs_get, w ;make address of where to read new byte from
        movwf   fsr0        ;point to where to read the byte from
        movpf   indf0, data ;get the data byte and pass it back

        decf    name + fifo_ofs_n ;indicate one less byte now in the FIFO
        movlw   size        ;get offset for last byte in buffer
        dcfsnz  name + fifo_ofs_get ;update buffer index, skip on not wrap
        movwf   name + fifo_ofs_get ;wrap back to end of buffer
        exitm
   endif

        error   "Macro FIFO_PUT not implemented for this processor"
        endm


part 3 330 bytes

********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam.....embedinc.com, http://www.embedinc.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\03\21@062435 by Edson Brusque

face
flavicon
face
Hello,

   thank you all that replied.

   I've decided to not use FIFO buffer (for now) in that application
because it would use alone more instruction cycles than my data-rx function
is using right now.

   Anyway, I'm saving all the comments because it will be very usefull in
the near future.

   Best regards,

   Brusque

-----------------------------------
Edson Brusque
Research and Development
C.I.Tronics Lighting Designers Ltda
(47) 323-2685  /  (47) 9993-6453
Blumenau  -  SC  -  Brazil
http://www.citronics.com.br
-----------------------------------

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu with SET PICList DIGEST in the body


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...