1

I'm facing some issues regarding Writing and Receiving data from another device. Unfortunately there is not a lot of documentation available about the device I'm trying to communicate with. All the documentation I received is the following:

Wiring
- Ground
- Single wire async communication

Byte Format
- Asynchronous 
- Half duplex
- 38.4kbps +/- 1.75%
- 1 start bit
- 8 data bits
- lsb first
- 1 parity bit (even)
- 2 stops bits

Checksum
- The last byte of the packet contains the packet checksum, which is calculates by summing the previous bytes of the packet and then 1's complementing the answer.

Startup Packet
- 1 Byte for Header (HEX 53, ASCII S)
- 1 Byte for Checksum
- Total 2 Bytes send @38.4kbps (0.624ms)

- The Startup response should me executed every 10ms until there is a valid response

Startup Response
- 1 Byte for Header (HEX 73, ASCII s)
- 1 Byte for settings (0-7 bits)
- 1 Byte for settings (0-7 bits)
- 1 Byte for Checksum
- Total 4 Bytes send @38.4kbps (1.248ms)

Based on the information above, I've setup my Arduino MEGA 2560 with the schematic and code below. Every 10ms I send the Startup Package, but I don't receive a single response. I also tried multiple Checksum Calculations but none of them are working. I expect the is probably an issue with Checksum, Baudrate or Wiring. But not sure where too look anymore.

My current Test Code:

int incomingBytes[2];
int index = 0;
//byte dataArraySendStartup[] = {0x53, 0x53};
unsigned long newmicros, oldmicros;
const long DELAY = 9996;   // 10 ms;


void setup() {
  Serial.begin(500000);
  Serial3.begin(38400, SERIAL_8E2);
  oldmicros = micros();
}



void loop() {

  //Send serial Bytes in code block below
  newmicros = micros();
  if (newmicros - oldmicros >= DELAY) {
    if (newmicros - oldmicros != DELAY){
        oldmicrosByte = micros();
        Serial3.write(0x53);
        Serial3.write(0x3A);
        newmicrosByte = micros();
        Serial.println(newmicros - oldmicros);

        oldmicros = newmicros;
    }
   
  }


  //Write serial Bytes to Serial Monitor
  if(Serial3.available()>0){
    incomingBytes[index] = Serial3.read();    
    Serial.println(incomingBytes[index], HEX);
    index++;
  }

  //Reset the incoming bytes
  if(index == 2) {
    index = 0;  // reset index so we don't overwrite next time
  }  
}

My current Schematic: enter image description here

7
  • you may have a long wait for an answer, because you did not ask a question ... this is not a forum, it is a Q&A site
    – jsotola
    Aug 1 at 0:10
  • Don't you receive the echo of the bytes you are sending? Aug 1 at 10:06
  • 2
    The ones component of 0x53 is 0xAC...
    – Majenko
    Aug 1 at 15:38
  • 1
    Your circuit seems wrong, as RXD is always equal to TXD because of the direct connection. TXD is active high during idle times. Aug 2 at 9:35
  • Thank you @thebusybee, do you have any advise for an alternative solution? I know that some other schematics uses an XOR Gate, with input 1 the TX/RX (Combined) and on input 2 the Ground and the output goes to the TX on the MEGA. But that felt really weird to me to connect the TX to and Output of an XOR Gate, also I have to order an XOR Gate. Do you think that's gonna work or do I need to change something else in my Schematics? Thank you!
    – J Quest
    Aug 2 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.