Related to this question I'm learning to use the Pi GPIO and Python serial to communicate through an IC (L9637D) to interrogate PIDs for alarms etc. I can't get past the slow initiation sequence!
The ISO 9141-2 slow init method used with Arduino and other MCs with L9637D and similar) is as follows:-
- wait a minimum of 2600ms after car is turned on (ECU init).
- Send byte 0x33 to the K-Line at 5 baud, serial communication (18N1).
- Initialize UART (18N1) to 10.4K baud, Receive byte 0x55 from the vehicle.
- Receive two key bytes (08 08 or 94 94)
- Wait for about 40ms
- Invert key byte 2 and send back to ECU i.e 0x08 becomes 0xF7.
- Wait another 40 milliseconds.
- Receive inverted address byte 0x33 i.e. 0xCC.
I realise I'm reinventing the wheel and could buy/download a solution but I'm trying to learn Python and GPIO on the Pi.
I've done minicom loopback tests etc but cannot get past slow init step 2. minicom returns stream of characters like '%' or series of 0x00 with some 0xFF. To test I used variants of this code using sleep 0.2 etc :-
#!/usr/bin/env python3 import time import serial ser = serial.Serial( port='/dev/ttyAMA0', baudrate = 5 # not 4800, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) print(ser) ser.write(serial.to_bytes([0x33])) # try to_bytes time.sleep(0.2) ser.close()
To debug I tried attaching a digivoltmeter to UARTS and saw only tiny fluctation in 3.3v. So I'm guessing UART cannot make necessary rapid low/hi waveform @ 5 baud.
I started to use pigpio to switch mode IN / ALT0 and baudrate but realised this might be wrong way too. So my questions:
a. Should I create a slow init waveform using pigpio, maybe using other GPIOs then use UARTs to receive slow inti at 5baud then 10k4 baud ?
EDIT 1 : below is output of piscope at 5 baud and minicom when running test_write.py . As I understand this byte 0x33 at 5 baud should take about 2 seconds (200ms low, 400ms hi/low/hi/lo, 227ms hi) so something seems wrong with baudrate
It seems minimum baudrate for pigpio is 50 so I may have to use some other trick - I see some people lowering base frequency but this may cause an issue when I need to step back to standard 10k4 baud.
Any guidance welcomed. Andrew.