Shop OBEX P1 Docs P2 Docs Learn Events
Need SERIN/SEROUT code help — Parallax Forums

Need SERIN/SEROUT code help

SteelSteel Posts: 313
edited 2009-07-23 22:18 in Propeller 1
I am doing something which I thought would be easy...but the propeller is not liking it...Obviously, it is probably my issue, but I can't figure out what is wrong here...it should be easy.

I am using a PC sending a command down to the Propeller dev kit.
I have the BS2.Serin_Char to recieve the command and save it as a variable, "MODE".
I then use the BS2.Serout_Char command to send "MODE" up to the PC.

I send down 0xAA.· I recieve back 0x1B.

When I monitor the pins on the propeller, I see the 0xAA on the RX pin and I see 0x1B on the Propeller TX Pin.· For some reason, "MODE" is not storing the 0xAA and sending it back.

I have attached my scope trace showing 0xAA being recieved and 0x1B being sent.
Can someone help me?· Here is my code:





CON
· _CLKMODE = XTAL1 + PLL16X
· _CLKFREQ = 5_000_000

OBJ
·
· BS2 : "BS2_Functions.spin"
·
·
·
·
VAR
······· Byte MODE, X
PUB MAIN
·
·
·· MODE := 00
· REPEAT·
······· MODE := BS2.SERIN_CHAR(31, 9600, 1, 8)

······· CASE MODE
········· $0:
·········· 'Triggers Reset
········· $1:
·········· 'ProgPin Low·····················
········· $2:
·········· 'ProgPin High
········· $3:
·········· 'Shiftout
········· $4:
·········· 'ShiftIn
·······

······· BS2.SEROUT_CHAR(30, MODE, 9600, 1, 8)
·····
DAT

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2009-07-23 19:59
    I don't know if it matters for this case but the BS2 function library has a start method that is not called in your code. Well I just looked at the code and the start method sets a variable used in a routine called by serialin_char.

    John Abshier
  • TimmooreTimmoore Posts: 1,031
    edited 2009-07-23 20:04
    Another problem I can see if when you call serin_char you must call it before the char has started to be sent from the PC. I dont see how you do this. So it you call serin_char part what through the char being sent you will receive a different char.
  • SteelSteel Posts: 313
    edited 2009-07-23 21:20
    I added the start method to my code, and it does not improve it. The Propeller still sends back 0x1B.

    The PC (right now) is sending 0xAA every 100mS.· My loop in propeller code runs and then waits for the next message, so I can see it maybe being wrong on the first one but it is wrong on every message.· Also, 0x1B isn't a 'partial' message of 0xAA.

    Am I assigning the SERIN to the variable correctly?
    If I put in "MODE := $AA" in the line just above the SEROUT, The PC recieves 0xAA.· But It does not recieve 0xAA when I assign·the·SERIN to Mode...so it leads me to believe that something is wrong with "MODE := BS2.SERIN_CHAR(31, 9600, 1, 8)"

    Grrrr
  • TimmooreTimmoore Posts: 1,031
    edited 2009-07-23 22:08
    I think what I would do is add this

    dira [noparse][[/noparse] 7..0 ] := 1
    to the start of the code
    and
    outa [noparse][[/noparse] 7..0 ] := mode
    after the serin
    then you can look at pins 0 to 7 to see what was received by the prop
    That would confirm if its the receive side that having the problem
  • John AbshierJohn Abshier Posts: 1,116
    edited 2009-07-23 22:18
    When I send data to the PC with FullDuplexSerial I use mode 0. Try
    BS2.SEROUT_CHAR(30, MODE, 9600, 0, 8)


    John Abshier
Sign In or Register to comment.