PROS Generic Serial Troubleshooting

I want to share 32-bit signed integers between the V5 brain and an Adafruit Feather RP2040 over the smart ports. This is the current circuit diagram (RP2040 is simplified):

Datasheet for the SN75HVD3082EP RS-485 transceiver chip

When I send bytes from the RP2040 over to my PC over USB serial, all the bits are correctly received and as expected. However, when I connect the RP2040 as shown in the diagram, I receive no bytes in the serial receive buffer. If I plug/unplug the TX connection on a breadboard I do receive a junk byte on the brain.

Code running on the brain:

#include "main.h"
#include "pros/serial.hpp"
#include <bitset>

void initialize() {}

void disabled() {}

void competition_initialize() {}

void autonomous() {}

void opcontrol() {
  pros::Serial mySerial{1, 115200};
  mySerial.flush();

  while (true) {
    while (mySerial.get_read_avail() == 0) {
      pros::delay(1);
    };
    std::cout << std::bitset<32>(mySerial.read_byte()).to_string() << "\n";
  }
}

The output is nothing because it is waiting at while (mySerial.get_read_avail() == 0)

Code running on the RP2040 (is working properly):

#include <Adafruit_NAU7802.h>

Adafruit_NAU7802 nau;

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  while (!Serial) {
    delay(1);
  }
  nau.begin();

  nau.setLDO(NAU7802_3V0);
  nau.setGain(NAU7802_GAIN_16);
  nau.setRate(NAU7802_RATE_80SPS);

  // Take 10 readings to flush out readings
  for (uint8_t i = 0; i < 10; i++) {
    while (! nau.available()) delay(1);
    nau.read();
  }

  nau.calibrate(NAU7802_CALMOD_INTERNAL);
  nau.calibrate(NAU7802_CALMOD_OFFSET);
}

void loop() {
  while (!nau.available()) {
    digitalWrite(LED_BUILTIN, LOW);
    delay(1);
  }
  digitalWrite(LED_BUILTIN, HIGH);
  int32_t num = nau.read();
  
  uint8_t* bytes = reinterpret_cast<uint8_t*>(&num); // Only 4 long

  uint8_t arr[8];

  for (int8_t i = 0; i < 4; i++) {
    uint8_t lsMask = i * 2 << 4;
    uint8_t ls = (bytes[i] & 0B00001111) | lsMask;

    uint8_t msMask = (i * 2 + 1) << 4;
    uint8_t ms = ((bytes[i] >> 4) & 0B00001111) | msMask;

    arr[i * 2] = ls;
    arr[i * 2 + 1] = ms;
  }
  Serial.write(arr, 8);
}

Is there something I’m missing so the brain’s serial receive buffer isn’t filling up? It could be the case that there is no signal being sent out of TX, that the RS-485 chips are busted or miswired, the smart cable is bad, a programming issue, or something else. Too bad I don’t have a logic analyzer or scope.

in what order are the wires crimped on the other end of the smart cable (the part plugged into the brain)? Are you getting power as expected when you plug the circuit into the brain?

1 Like

(Looking so that the clip is facing away from me, from left to right) black, red, green, yellow. Yes, I have a 13V potential between Yellow and Green which powers the L7805 as expected. The 5V output is there, and the Feather can turn on and run a blink sketch.

Turns out I had to use Serial1 on the RP2040. Serial is for USB only! :man_facepalming:

2 Likes