Skip to content

Arduino due doesn't seem to work #44

Open
@racarla96

Description

@racarla96

I am trying to see how the library works and I am trying to see what happens onReceive by trying to see the output through another serial port (arduino Due), this would be the code. Is there something I'm doing wrong or don't know? Thank you

#include <TinyProtocol.h>
// We need this hack for very small controllers.
#include <proto/fd/tiny_fd_int.h>

/* Creating protocol object is simple. Lets define 48 bytes as maximum. *
   size for the packet and use 4 packets in outgoing queue.             */
tinyproto::Fd<FD_MIN_BUF_SIZE(48, 4)>  proto;

void onReceive(void *udata, tinyproto::IPacket &pkt)
{
  Serial3.println("-----------------");
//  for (int i = 0; i < pkt.size(); i++)
//  {
//    Serial3.print(pkt.getByte());
//    Serial3.print(" ");
//  }
//  Serial3.println();
  
  if (proto.write(pkt) == TINY_ERR_TIMEOUT )
  {
    // Do what you need to do if there is no place to put new frame to.
    // But never use blocking operations inside callback
  }
}

void setup()
{
  /* No timeout, since we want non-blocking UART operations. */
  Serial.setTimeout(0);
  /* Initialize serial protocol for test purposes */
  Serial.begin(115200);
  /* Lets use 8-bit checksum, available on all platforms */
  proto.enableCheckSum();
  /* Lets process all incoming frames */
  proto.setReceiveCallback( onReceive );
  /* Redirect all protocol communication to Serial0 UART */
  proto.begin();

  Serial3.begin(115200);
  Serial3.println("START");
}

void loop()
{
  if (Serial.available())
  {
    Serial3.write(".");
    Serial3.flush();
    proto.run_rx([](void *p, void *b, int s)->int { return Serial.readBytes((uint8_t *)b, s); });
  }
  proto.run_tx([](void *p, const void *b, int s)->int { return Serial.write((const uint8_t *)b, s); });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions