First of all I want to introduce myself. I´m currently developing a LIN communication board and as I don´t have much experience in AVRs I´ve been experienced problems with it.
I have some troubles when I try to use the ATmegaM1 LIN/UART controller in LIN mode.
I´m using the Atmel Appnote AVR286: LIN Firmware Base for LIN/UART Controller to test the controller.
The problem is that, when I try to transmit a frame using lin_tx_header() or lin_tx_response(), LIN bit error (LBERR) interrupt flag in LINERR register is set.
According to datasheet:
"LBERR = LIN Bit ERRor A unit that is sending a bit on the bus also monitors the bus.
A LIN bit error will be flagged when the bit value that is monitored is different from the bit value that is sent. After detection of a LIN bit error the transmission is aborted."
I dont know what this exactly means, if only compares bit value or if it takes bit timing also into account.
So, after that I decided to use the listen mode of the controller:
"The listening mode connects the internal Tx LIN and the internal Rx LIN together.
In this mode, the TXLIN output pin is disabled and the RXLIN input pin is always enabled. The same scheme is available in UART mode."
And, surprise!, it works fine(Or that is what I suppose, because TXOK interrupt flag was set).
I also tried to put UART commands instead of LIN and the communication works fine too (in normal mode), so I guess the problem is the LIN.
Debugging with JTAGICE mkII and IAR, the bit error interrupt flag is set when the program tries to write a LIN tx command.
I´ve also tried pulling-up tx pin externally but it doesn´t work.
The ATmega is programmed via ISP, and the programming MOSI is the same pin as TXLIN (PD3-->PCINT19/TXD/TXLIN/OC0A/SS/MOSI_A), and I´ve trying disconnecting this pin from the programmer once the device is programmed, but the error dont dissapear.
Thanks a lot for your time.