Sending HEX over serial.

I am trying to recreate some RS485 signals that the gauge cluster in my car is expecting in order to control some no longer used gauges.
I have captured the data structure and now want to try replicating it with an Arduino Pro Mini 5v driving an LTC1487 RS485 line driver.
I have wired up the driver and it is working as expected, however, when I hook my scope up to the output I am not seeing what I would expect.

I have a string of Hex values that I want to send and I cannot seem to get the correct variable types or data types with Serial.print().
For the sake of testing, I have started with a single value "E1" which should have a binary value of 11100001 or a decimal value of 225.
When I store 225 as a byte or E1 as a char I never get the expected 11bit packet (start bit, 8 bit payload, even parity, and stop bit).
If I just use serial.print() I end up getting the binary value for 2, then 2, then 5 so 33 bits, if I set the data type in serial.print() to BIN I get the data values for 1,1,1, 0,0,0,0,1 or 88bits.

Can anyone suggest which combination of variable type and data type for serial.print() I would need to send the desired 11bit package?

Here is the test code I am using:

const int txEnablePin =  8;   // LTC1487 mode control pin HIGH = tx enabled, LOW = RX enabled
int enableState = HIGH;
byte x = 225;
void setup() {
  // initialize serial communications at 9600 baud 8,E,1 
  Serial.begin(9600, SERIAL_8E1);
  // set the LTC1487 to Tx mode
  digitalWrite(txEnablePin, enableState);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print(x);
  delay(5000);
}

Try "serial.write()".
Paul

BStanley346:
I am trying to recreate some RS485 signals that the gauge cluster in my car is expecting in order to control some no longer used gauges.
I have captured the data structure and now want to try replicating it with an Arduino Pro Mini 5v driving an LTC1487 RS485 line driver.
I have wired up the driver and it is working as expected, however, when I hook my scope up to the output I am not seeing what I would expect.

I have a string of Hex values that I want to send and I cannot seem to get the correct variable types or data types with Serial.print().
For the sake of testing, I have started with a single value "E1" which should have a binary value of 11100001 or a decimal value of 225.
When I store 225 as a byte or E1 as a char I never get the expected 11bit packet (start bit, 8 bit payload, even parity, and stop bit).
If I just use serial.print() I end up getting the binary value for 2, then 2, then 5 so 33 bits, if I set the data type in serial.print() to BIN I get the data values for 1,1,1, 0,0,0,0,1 or 88bits.

Can anyone suggest which combination of variable type and data type for serial.print() I would need to send the desired 11bit package?

Here is the test code I am using:

const int txEnablePin =  8;   // LTC1487 mode control pin HIGH = tx enabled, LOW = RX enabled

int enableState = HIGH;
byte x = 225;
void setup() {
  // initialize serial communications at 9600 baud 8,E,1
  Serial.begin(9600, SERIAL_8E1);
  // set the LTC1487 to Tx mode
  digitalWrite(txEnablePin, enableState);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print(x);
  delay(5000);
}

With serial.print Bytes are sent as a single character.
Is it possible to use the available following switches?
Serial.print(xx, BIN)
Serial.print(xx,OCT)
Serial.print(xx,DEC)
Serial.print(xx,HEX)
For the same xx the results will be different.
Thanks

Paul_KD7HB:
Try "serial.write()".
Paul

That did it!!
Thank's Paul.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.