I am trying to use the RPi as a LIN Master to communicate with a number of slave nodes on the LIN bus. I can send the correct bytes, starting with the sync byte of 0x55, and then the node ID, the message data and the checksum. In order for the nodes to listen, I need to send zeros for at least 13 bittimes prior to the sync byte. In pyserial, the port is set to eightbits, so, of course, I can only send 8 zeros when I need at least 13. Any ideas for solving this?
hey I want to try the same thing. I red the aplication note "avr322: LIN v1.3 Protocol Implementation on Atmel AVR Microcontrollers". There is defined that the Sync Delemiter can be in range from 1 to 4 Tbit. So it should be possible to set the baud rate to 9/13 of the original and send 0x00. That should result in a 13bit low and a 1.444 bit long stop bit (given that you used 1 stop bit in config). Then set the baudrate back to the original one and start sync. I havened tested this yet but i think thats the way to go.
I have used Lin togheter with Arduino. There the solution is to use a software serial port on one of the digital I/O's. In order to get the start sequence of 13 low bits, the serial connection is stopped, and the pin is put low for a defined amount of time, after which the serial connection is started again. Maybe the pyserial van be used in the same way.
if you don't have extended UART to put this break, try to switch baud rate. Send break on half the baud rate, then switch back to normal baud rate. I'm using this princip on ATMEL ATmega chips. It worx.
You could implement a logical AND between the TX pin and a regular GPIO, then use the GPIO to generate the LIN break:
A basic AND game can be made with a resistor and two diodes.
Sending a LIN frame would look like this:
# setup serial = Serial("/dev/serial", 19200); GPIO.setup(BRK_PIN, GPIO.OUT) GPIO.output(BRK_PIN, GPIO.HIGH) # sending GPIO.output(BRK_PIN, GPIO.LOW) time.sleep(0.001) GPIO.output(BRK_PIN, GPIO.HIGH) serial.write(LIN_FRAME)