Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial1.write(buf, len) (FAIL) #28

Open
SeanMWX opened this issue Feb 18, 2024 · 0 comments
Open

Serial1.write(buf, len) (FAIL) #28

SeanMWX opened this issue Feb 18, 2024 · 0 comments

Comments

@SeanMWX
Copy link

SeanMWX commented Feb 18, 2024

Problem description:
I am encountering an issue with Serial1.write(buf, len) where the number of bytes received does not match the expected length during Serial1 communication between two Arduino devices with TX and RX pins cross-connected.

Setup for Arduino 1:

  1. Initialized a buffer "uint8_t au8Buffer[64]" and assigned values to the first eight elements.
  2. Attempted to send the first eight elements via "Serial1.write(au8Buffer, 8)", expecting to transmit 8 bytes.

Setup for Arduino 2:

  1. Configured to listen for incoming Serial1 communication.

Expected behavior:
Arduino 2 should receive exactly 8 elements when Arduino 1 sends a length of 8.

Observed behavior (See figures below):

  1. When sending with "len = 8", Arduino 2 receives only 7 elements.
    Screenshot from 2024-02-18 21-37-04

  2. Increasing the send length to "len = 9" results in the correct reception of 8 elements.
    Screenshot from 2024-02-18 21-40-45

This behavior is not consistent with my understanding of the Serial.write() documentation and intended functionality.

Additional:
Arduino IDE version: 2.3.1
Code for Arduino 1:

uint8_t au8Buffer[64];

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
  au8Buffer[0] = 1;
  au8Buffer[1] = 3;
  au8Buffer[2] = 0;
  au8Buffer[3] = 1;
  au8Buffer[4] = 0;
  au8Buffer[5] = 4;
  au8Buffer[6] = 21;
  au8Buffer[7] = 22;
}

void loop() {
  Serial1.write(au8Buffer, 8);  // len = 8 only sent first 7 elements ...???
}

Code for Arduino 2:

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if(Serial1.available()) {
    Serial.println(Serial1.read());
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant