Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: SerialLink

  1. #1
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    407

    SerialLink

    All, I made a Serial transfer library intended to be used between two Teensy devices, it might be useful to you:
    https://github.com/bolderflight/SerialLink

    The unique aspect of this library is that:
    1. The sender typically expects an Ack response to any messages sent.
    2. The receiver automatically sends an Ack if a good message is received.

    I use Frank's FastCRC library for computing CRC-16 as part of the message:
    https://github.com/FrankBoesing/FastCRC

    The messages are somewhat like HDLC in that I use single byte framing bytes to signal the start and end of a message. Escape characters are used to prevent those framing bytes from occurring anywhere within the message body.

    I think usage is simple. Objects are already provided for use with Serial1, Serial2, and Serial3 - Serial1Link, Serial2Link, and Serial3Link respectively. A begin method is used in setup to set the baud rate; in the example on github I use 6 MBaud

    onReceive is used to specify a callback for the message handler you would like to use on receiving a good message.

    Messages are built starting with a beginTransmission() method followed by write(unsigned char) or write (unsigned char *data, unsigned int len) to write single bytes or buffers to the transmission buffer. endTransmission is called to send the message. endTransmission is a blocking method and will wait until it receives an Ack reply, automatically resending the message periodically. Optionally, endTransmission(unsigned int timeout) will wait for an Ack up to timeout microseconds. Finally, sendTransmission() provides a non-blocking method. If sendTransmission() is used, getTransmissionStatus can be used to check whether an Ack has been received.

    Messages are read with the typical available and read methods. available() returns the number of bytes in the message buffer, read() returns a single byte from the buffer, and read(unsigned char *data, unsigned int len) copies len bytes from the message buffer to the data buffer.

    At some point in the future, I'd like to implement requestFrom and onRequest type functionality.

    Again, hope it helps some of you! I'd appreciate hearing if you find any bugs or have suggestions for code improvements or additional functionality.

    Brian

  2. #2
    Senior Member pictographer's Avatar
    Join Date
    May 2013
    Location
    San Jose, CA
    Posts
    635
    Sounds good! Would DMA be useful?

  3. #3
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    407
    Quote Originally Posted by pictographer View Post
    Sounds good! Would DMA be useful?
    I don't know enough about DMA - I think for receiving messages it would be hard because I don't know the message length. But for sending messages it might be useful. I should probably look at how i2c_t3 uses DMA because it must have similar issues.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •