checksum function for sending serial bytes

Hi all. Been away from propeller for a while and a little rusty now.
What I'm needing to do is send a byte stream to a 4D display. This will be 6 bytes. Five data and one checksum. Id like to make a function that accepts the 5 bytes and makes a checksum and then sends the 6 bytes out serial. What would be the best way to go about this? The checksum is just the 5 byte xor'd together.
I think I would start another PUB and then call it from the main with 5 parameters?
Any quick examples to start with would be appreciated.


  • CRST1CRST1 Posts: 101
    edited 2019-11-04 05:08
    Also fullduplexserial has a tx(byte) function. I'm a little confused on how to send multiple bytes. I have sent separate tx commands one after the other. Is there a way to send multiples like tx(1A, 9C. 10) or tx.byte(19 & 10 & 32).
    I saw someone said use tx.str(string($80, 2, 2)) aslong as not sending 0
    I will need to send 0.

  • Tracy AllenTracy Allen Posts: 6,545
    edited 2019-11-07 19:38
    You can add a method to fullDuplexSerial or to your main code, to send a counted string:
    PUB StrN(stringptr,nchar)
    '' Send counted string, nulls okay
      repeat nchar
    That is pretty much the way you are doing it. tx[byte] at a time. There is also a way to transfer packets, multiple bytes at once to the transmit buffer, using bytemove instructions. That is useful for high baud rates and large packets, but for your purposes one tx[byte] at a time may well be fast enough.

    For the checksum, you could roll it into the transmit routine.
    PUB StrN(stringptr,nchar) : check | bite
    '' Send nchar counted string, append simple checksum
      repeat nchar
         bite := byte[stringptr++]
         check := check ^ bite
         [s]tx(byte[bite])[/s]  tx(bite) .  ' per comments below
  • Thanks I'll start with this and see what I can do
  • ZootZoot Posts: 2,227
  • yes
  • Right about that, bite is local.
  • Right about that, bite is local.

    no, bite is already the char, byte[stringptr++], so the second invoke of byte[..] is not needed.

    nothing to do with local or global.


  • kwinnkwinn Posts: 8,679

Sign In or Register to comment.