EmbeddedRelated.com
Forums

Using UART to send/receive LIN frame in LPC2378.

Started by Aji P August 21, 2010
Sorry i pressed the wrong button to start a new topic. :D

> AFAICT, LIN have been designed to be implemented with standard UART
> easily. Implementing it with CAN or SPI may be next to impossible.
Yes. I've read in many references, that UART can be used to send LIN frame.

> I think that you have to set BREAK signal and then count the
> necessary 13-bit time yourself. Furthermore, I suspect, that, after you
> release the BREAK, you must count at least one bit time before you send
> the SYNC frame.
Do you mean that, i could send LIN break without using any "virtual" baudrate? Just send a normal UART break, count 1 bit time, and send other LIN fields ? Hmmm... i would try it. :D

Other approach that I've read in other topic, that i should change UART baudrate before sending break signal by using a "virtual" baudrate that simulates 13-bit char of LIN's break, and before sending other LIN fields, i set the UART baudrate to it's previous value. I'm still trying on it now. Even though i was previously expect that i could change break length by using UART0 registers.

BTW, i'm still confuse, Timo. Just to make sure... break signal is 0x00 data ? If I use UARTSend function to send break, will it add start bit and stop bit ? Or maybe i could use Break Control, because in LPC Datasheet, there is Break Control (value 1 is Enable Break Transmission) in Line Control Register (U0LCR for UART0), if I set 1 to Break Control of LCR, will UART0 sends break automatically ?

Without using "virtual baudrate", after trying to send some data, I find out that some are correctly arrived at the receiver, but some are not correct. I wish i had an oscilloscope. :D

UART1 in LPC has RS232 support for modem connection, but UART0 doesn't have it. Which one is better for LIN ?

Thank you.

--- In l..., Timo wrote:
>
> On 08/21/2010 07:15 AM, Aji Pamungkas wrote:
> > Hello, lpc2000 users.
>
> When you start a new topic, please don't write a reply to an old thread.
> Write a new message instead.
>
> > i'm trying to use UART0 as LIN ...
>
> I have not implemented LIN anywhere yet but anyway...
>
> > Can I use UART in LPC2378 to send/receive LIN message, or should I
> > use CAN or SPI instead ?
>
> AFAICT, LIN have been designed to be implemented with standard UART
> easily. Implementing it with CAN or SPI may be next to impossible.
>
> > I think it's because the UART break signal, LIN use 13 bits and UART
> > use 11 bits (CMIIW), but how to change bit length in UART to 13
> > bits, can I change it ? or should i make software functions to
> > handle this?
>
> How do you try to send BREAK. Where do you expect that that 11-bit time
> comes from? I think that you have to set BREAK signal and then count the
> necessary 13-bit time yourself. Furthermore, I suspect, that, after you
> release the BREAK, you must count at least one bit time before you send
> the SYNC frame. Otherwise receivers can't tell properly where BREAK ends
> and SYNC starts.
>
> Can't you look at the signal with a scope and see what's going on?
>
> --
>
> Timo
>

An Engineer's Guide to the LPC2100 Series

On 08/22/2010 02:03 AM, Aji P wrote:
> > I think that you have to set BREAK signal and then count the
> > necessary 13-bit time yourself. Furthermore, I suspect, that, after you
> > release the BREAK, you must count at least one bit time before you send
> > the SYNC frame.
> Do you mean that, i could send LIN break without using any "virtual"
> baudrate? Just send a normal UART break, count 1 bit time, and send
> other LIN fields ? Hmmm... i would try it. :D

Yes, but of course keep BREAK set for 13 bit times, release BREAK and
wait at least 1 bit time before starting to send other fields.

But remember, that this is all just theory from my part.

> Other approach that I've read in other topic, that i should change UART
> baudrate before sending break signal by using a "virtual" baudrate that
> simulates 13-bit char of LIN's break, and before sending other LIN
> fields, i set the UART baudrate to it's previous value. I'm still trying
> on it now. Even though i was previously expect that i could change break
> length by using UART0 registers.

Ok, that is something I couldn't think about. It may work. When you send
a normal 0x00 data byte, TX line will be low (TTL side of the
transceiver) for 9 bit times (with 8N1 parameters). So, the virtual baud
rate should be selected so that those 9 bits are as long as 13 bits with
real baud rate.

> BTW, i'm still confuse, Timo. Just to make sure... break signal is 0x00
> data ?

Sort of. When receiver sees 9 bits of zeros, thats normal 0x00 data.
10th zero makes it framing error. Only 11th zero makes it BREAK signal.
13 bit time requirement makes it sure that all receivers see the signal
as BREAK even with slightly differing baud rates.

> If I use UARTSend function to send break, will it add start bit
> and stop bit ?

I don't know how that function works but I suspect that if you give it
0x00 to send, it sends normal 0x00 data with start and stop bits - which
is not break (unless you change the baudrate)

> Or maybe i could use Break Control, because in LPC
> Datasheet, there is Break Control (value 1 is Enable Break Transmission)
> in Line Control Register (U0LCR for UART0), if I set 1 to Break Control
> of LCR, will UART0 sends break automatically ?

No, in the sense that it only keeps the TX line low. You must count the
time yourself. At least that is my theoretical understanding now.

I'm sorry that I have no hands-on experience to share but I'm curious to
know, how you will get it working...

--

Timo