Shop OBEX P1 Docs P2 Docs Learn Events
Buffered TX and RX (SX/B + Assembly) — Parallax Forums

Buffered TX and RX (SX/B + Assembly)

JonnyMacJonnyMac Posts: 9,276
edited 2007-08-10 16:50 in General Discussion
My purpose in sharing this is two-fold:

1) I needed it; someone else may as well.

2) To demonstrate that with very little effort we mortals can take code from gurus like Guenter, Peter, etc., and fold it into our SX/B programs. Terry has done a great job constructing SX/B to allow the smooth incorporation of Assembly segments and I think this is a pretty good demonstration of that.

Notes:
-- TX and RX [noparse][[/noparse]circular] buffers are each eight bytes
-- TX and RX vars and code are independent of each other and can be pulled out and used separately
-- code prevents overrun of buffers when full
-- DELAY_MS used to replace PAUSE -- allows RX and TX while performing the delay

I've tested at the limits: 1200 and 38400 baud. Please let me know if you find any issues as this is getting folded into the latter chapters of my book. Thanks.

Comments

  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-08-10 15:04
    JonnyMac,

    When attempting to compile I got an error. See attached jpg screenshot.
    1280 x 1024 - 126K
  • BeanBean Posts: 8,129
    edited 2007-08-10 15:31
    You are using the BETA compiler.

    You'll have to add a "RETURN __PARAM1" before the ENDFUNC to satisfy the compiler.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • JonnyMacJonnyMac Posts: 9,276
    edited 2007-08-10 15:44
    Terry,

    Is that because the compiler expects the FUNC keyword to have an associated RETURN? I'm using 1.51.03 so I have not see the problem reported by T&E.
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-08-10 16:01
    That did it for me:
    ' -------------------------------------------------
    ' Subroutine / Function Code
    ' -------------------------------------------------
    ' Use: aByte = RX_BYTE
    ' -- returns "aByte" from 8-byte circular buffer
    ' -- will wait if buffer is presently empty
    ' -- rxBufCnt holds byte count of receive buffer (0 to 8)
    FUNC RX_BYTE
      ASM
        BANK  rxSerial
        TEST  rxBufCnt    ' check buffer count
        JZ    @RX_BYTE    ' wait if empty
        MOV   W, #rxBuf    ' point to tail
        ADD   W, rxTail
        MOV   FSR, W
        MOV   __PARAM1, IND    ' get byte at tail
        INC   rxTail    ' update tail
        CLRB  rxTail.3    ' keep 0 to 7    
        DEC   rxBufCnt    ' update buffer count
        BANK  0
      ENDASM
      [b]RETURN __PARAM1[/b]
      ENDFUNC
    
  • BeanBean Posts: 8,129
    edited 2007-08-10 16:31
    JonnyMac said...
    Terry,

    Is that because the compiler expects the FUNC keyword to have an associated RETURN? I'm using 1.51.03 so I have not see the problem reported by T&E.
    Jon,
    · Yes, it is expecting to see a RETURN somewhere within FUNC...ENDFUNC (I'll have to change the wording of the error message since it references ENDSUB which CAN be used without a return).

    · It probably should be a warning instead of an error, since it doesn't prevent anything from compiling.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • JonnyMacJonnyMac Posts: 9,276
    edited 2007-08-10 16:50
    I agree that it should just be a warning; in cases like this program where the FUNC is all assembly (and __PARAMx is being dealt with manually), there is no need for the RETURN keyword.
Sign In or Register to comment.