Hi,
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: