LIN Slave Auto-Baud Function on AVR128DA

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!,

 

i'm currently working on project that uses the lin bus.

I can already receive the identifier from the master device when the correct baud rate is set. I already activated the 'LIN AUTO' RXMODE for auto baud detection, but as soon i change the baud rate on the master device it is not working anymore. The 'USART_ISFIF' bit is set, so the sync failed. I also already checked the sync byte and it is correct (0x55).

I think there is something missing i have to do.

 

Does anyone have a hint for me? smiley

#define USART0_BAUD_RATE(BAUD_RATE) ((float)(F_CPU * 64 / (16 * (float)BAUD_RATE)) + 0.5)
#define MAX_BUFFER_SIZE 32
uint8_t buffer[MAX_BUFFER_SIZE];
uint8_t bufCount;

void init()
{
    bufCount = 0;

	PORTA.DIR &= ~PIN1_bm; //RX
	PORTA.DIR |= PIN0_bm; //TX

	USART0.BAUD = (uint16_t)USART0_BAUD_RATE(4800);

	USART0.CTRLC = USART_CHSIZE_8BIT_gc;
	USART0.CTRLA = USART_RXCIE_bm | USART_ABEIE_bm;

	USART0.CTRLB = USART_TXEN_bm | USART_RXEN_bm | USART_RXMODE_LINAUTO_gc;
}

ISR(USART0_RXC_vect)
{
	if((USART0.STATUS & USART_BDF_bm) == USART_BDF_bm)
	{
		//Break
	}

	if((USART0.STATUS & USART_ISFIF_bm) == USART_ISFIF_bm)
	{
		//Sync failed

		USART0.STATUS |= USART_ISFIF_bm;
	}

	while((USART0.STATUS & USART_RXCIF_bm) == USART_RXCIF_bm)
	{
		if(bufCount >= MAX_BUFFER_SIZE)
			bufCount = 0;

		buffer[bufCount++] = USART0.RXDATAL;
	}
}

 

This topic has a solution.
Last Edited: Sun. May 16, 2021 - 05:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


After the master changes the baud rate, is the break signal more than 12 bits at the old baud rate of the slave device?

Breaks that are too short will not trigger the auto baud rate.

 

Last Edited: Sun. May 16, 2021 - 01:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have 13 Bit for the break signal. Also tried higher values and changing the tolerance window.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What your question lacks:

Slave's old baud rate

Master's new baud rate

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For testing i tried following baud rates:

Old baud: 4800

New baud 9600

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

13 bits at 9600 bps will look like 6.5 bits to a slave operating at 4800 bps.
The error seen from the slave is 50%. Do you expect a reaction?

Last Edited: Sun. May 16, 2021 - 02:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 So i need to send 26bit? Can you please explain it more?

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The auto baud rate is for correcting small errors. It does not follow double baud rate changes.
First, use a communication command to notify the slave of the baud rate change.
The slave should change it to a provisional 9600bps and then fix the error with an auto baud rate from the master.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A very ridiculous way.

 

Set ABW to 25% tolerance and gradually increase the baud rate.

For example:

4800-> 5700-> 6800-> 8100-> 9600

 

Of course I've never done that, so it's just a theory.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Thank you very much for the explanation! smiley I missunderstood the auto baud function...