概述
Lin總線在汽車電子中使用非常廣泛,下面簡單介紹一下NXP MPC574X系列PowerPC的Lin總線配置。由于Lin總線的通信速率比較低,是以一般在實際開發中會使用DMA外設進行資料的搬運,減少MCU的等待時間。
Lin總線配置
波特率配置
如下圖所示,LinFlexD子產品的Baud Clock時鐘源為HALFSYS_CLK。

如下圖所示,HALFSYS_CLK為PLL輸出系統時鐘SYS_CLK的一半。及如果配置SYS_CLK為200MHz,HALFSYS_CLK則對應為100MHz。
由下面代碼可知,首先使Lin子產品退出Sleep Mode,并進入Init Mode,然後等待Lin進入Init Mode。
MegaHertz表示Lin子產品的Baud Clock的頻率,BaudRate表示要設定的總線波特率。
uint16_t Fraction,Integer;
LINFlexD_0.LINCR1.B.SLEEP = 0; /* Exit Sleep Mode */
LINFlexD_0.LINCR1.B.INIT = 1; /* Put LINFlex hardware in init mode */
/* wait for the INIT mode */
while (0x1000 != (LINFlexD_0.LINSR.R & 0xF000)) {}
BaudRate = (MegaHertz * 1000000) / BaudRate;
Integer = BaudRate / 16;
Fraction = BaudRate - (Integer * 16);
LINFlexD_0.LINIBRR.B.IBR= Integer; /* Mantissa baud rate divider component */
/* Baud rate divider = 100 MHz LIN_CLK input / (16*19200 bps) ~= 326 */
LINFlexD_0.LINFBRR.B.FBR = Fraction; /* Fraction baud rate divider comonent */