Hi all,
I am using a Mega2560 to interface with an automotive K-Line (ISO14230).
I have a working interface with a sketch using the SoftwareSerial class, but new shield/pin conflicts now have me using the hardware serial ports and HardwareSerial class, and pinning out from TX1/RX1 on pins 18/19.
Before sending data out, I need to perform a "Fast Initialization" of the bus line.
The TX line is set HIGH for 300 mSec, LOW for 25, HIGH for 25, then a packet addressed to the vehicle module is sent at 10400 baud.
My analyzer on TX1 isn't showing these digitalWrite() calls at all...
The scope starts LO, then goes
HI 0.4ms,
LO 356ms, (which looks like the period between .end() and .begin() calls)
HI 4.7 ms,
then data begins at 10400 baud.
I hope I'm missing something obvious to the more learned among you?
How should I be manipulating the TX1 line state on HardwareSerial?
Thanks,
-dave
HardwareSerial* k_line = &Serial1;
uint8_t tx_pin = 18, len = 3, data[] = {1,2,3};
k_line->end(); // empty i/o buffers; re-enable general pin i/o
pinMode(tx_pin, OUTPUT);
digitalWrite(tx_pin, HIGH); // K-line fast init T_idle = 300 ms
delay(300);
digitalWrite(tx_pin, LOW); // K-line T_init_L = 25 ms
delay(25);
digitalWrite(tx_pin, HIGH); // K-line T_init_H = 25 ms
delay(25);
k_line->begin(10400); // re-establish buffered i/o over digital pins
while(!k_line) ; // common practice but seems pointless?
for(uint8_t i=0; i<len; i++) k_line->write(data[n]); // works fine - data on scope