Shop OBEX P1 Docs P2 Docs Learn Events
Serin sx28 — Parallax Forums

Serin sx28

sumguy16sumguy16 Posts: 21
edited 2005-07-12 14:52 in General Discussion
I need two pass to variables to an SX28 via SERIN. I'm using a bluetooth module so I only have one RX. The variables I know can only be one byte at a time so I can have the value of the variables be between 0 and 255 , not a problem. I just need a solution that the SX28 will know the difference between the two variables. Any ideas?

Thanks,
Adam

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-12 12:13
    That's actually quite simple: create a subroutine to do your SERIN and then call it twice.· The SX28 runs fast enough that it will be able to deal with the variables in between transmissions.· As of version 1.3 you can use subroutines like functions in other languages:

    · myVar1 = GETBYTE
    · myVar2 = GETBYTE

    Here's the code for the GETBYTE subroutine:

    GETBYTE:
    · SERIN Sio, Baud, temp1
    · RETURN temp1

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • KenMKenM Posts: 657
    edited 2005-07-12 14:33
    Jon or anybody,
    I am not familiar with "use subroutines like functions"

    Is the end result that the subroutine is called and temp1 is returned to myVar1 and the same with myVar2?
    Thank you.


     
      myVar1 = GETBYTE
      myVar2 = GETBYTE
     
    GETBYTE:
      SERIN Sio, Baud, temp1
      RETURN temp1
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ken
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-12 14:52
    As of 1.3 SX/B can pass values back via W. When used like the example above, W gets loaded with temp1 at the end of the subroutine and then goes back to the caller where W is moved to the target variable. I thought I had made a big deal about this feature when it was released... clearly nobody pays attention to me -- unless I make a mistake! tongue.gif

    Here's the SX/B compiler output of a little test that shows the mechanics:

    Start:                           ;Start:
      MOV myBits,#$AA                ;  myBits = $AA  
      MOV __PARAM1,myBits            ;  myBits = INVERTBITS myBits
      CALL @__INVERTBITS            
      MOV myBits,W                  
      JMP $                          ;  END
    
    INVERTBITS:                      ;INVERTBITS:
      MOV temp1,__PARAM1             ;  temp1 = __PARAM1
      MOV W,/temp1                   ;  temp1 = ~temp1
      MOV temp1,W                   
      MOV W,temp1                    ;  RETURN temp1
      RETP 
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 7/12/2005 2:59:04 PM GMT
Sign In or Register to comment.