LINFlex Initialization

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LINFlex Initialization

3,472 次查看
bengtandersson
Contributor III

Hi!

 

I have a strange problem when initializing the LINFlex controller in MPC5602B. It seems like whenever doing this or changing the baudrate  setting in the controller it requires a delay before the controller can be used. A small delay of 50 ms seems to be enough.

 

Here is the initialization code:

 

void InitUart(const tUartId uartNr, const tBaudRate baud, tBuffer *const rxBuffer, tBuffer *const txBuffer)
{
tUartSettings * uart = &uarts[uartNr];


// configuration of LINLFEX periphial
uart->linflex->LINCR1.B.SLEEP = 0; // Disable LINFLEX sleep mode

uart->linflex->LINCR1.B.INIT = 1; // LINFLEX in init mode

// UART settings
uart->linflex->UARTCR.B.UART = 1; // Run LINFLEX in UART mode
uart->linflex->UARTCR.B.TDFL = 0; // 1byte buffer
uart->linflex->UARTCR.B.RDFL = 0; // 1byte buffer
uart->linflex->UARTCR.B.RXEN = 1; // rx enable
uart->linflex->UARTCR.B.TXEN = 1; // tx enable
uart->linflex->UARTCR.B.PCE = 0; // no Parity
uart->linflex->UARTCR.B.WL = 1; // 8bit data

// Baudrate configuration
uart->linflex->LINIBRR.B.DIV_M = baudMantissa[baud];
uart->linflex->LINFBRR.B.DIV_F = baudFraction[baud];

// Enable interupts
uart->linflex->LINIER.B.DRIE=1;
uart->linflex->LINIER.B.DTIE=1;

// start Linflex
uart->linflex->LINCR1.B.INIT = 0; // LINFLEX in run mode

//TODO: £R1 £F4 Check if I/Os needs to be configured as fast.
// Configure I/O pins pins
SIU.PCR[uart->txPcr].B.OBE = setBit; // Set pin as output
SIU.PCR[uart->txPcr].B.PA = uart->txPadAlterntaiveMode;

SIU.PCR[uart->rxPcr].B.IBE = setBit; // Set pin as input
SIU.PCR[uart->rxPcr].B.WPE = setBit; // Enable weak pulling device
SIU.PCR[uart->rxPcr].B.WPS = setBit; // Set to pull up

uart->txBuffer = rxBuffer;
uart->rxBuffer = txBuffer;

// Install interupt handlers
INTC_InstallINTCInterruptHandler(UartRxIntHandler,uart->rxInt,8);
INTC_InstallINTCInterruptHandler(UartTxIntHandler,uart->txInt,8);


uart->status = idle;
}

 

Here is the routine changing the baudrate. 

 

void ChangeBaudRate(const tUartId uartNr, const tBaudRate baud)
{
tUartSettings * uart = &uarts[uartNr];

uart->linflex->LINCR1.B.INIT = 1; // LINFLEX in init mode

// Baudrate configuration
uart->linflex->LINIBRR.B.DIV_M = baudMantissa[baud];
uart->linflex->LINFBRR.B.DIV_F = baudFraction[baud];

// start Linflex
uart->linflex->LINCR1.B.INIT = 0; // LINFLEX in run mode

}

 

 

 

Regards

Bengt

标签 (1)
0 项奖励
回复
2 回复数

2,572 次查看
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I have tested attached code on the MPC5604B EVB and I do not see any issue after initialization. Bytes are normally transmitted into PC. On-board transceiver is used. When I used external RS232 to USB cable, then sometimes first few bytes was corrupted.

Could this be a reason? What is your HW and how do you test the case?

BR, Petr

0 项奖励
回复

2,572 次查看
bengtandersson
Contributor III

HI!

This might be the reason to my problem. Is "few bytes corrupted" really OK?

I'm communicating with an onboard radio module (Digi XBee 868 LP). The "test" is simply when I try to send something to the radio directly after InitUart() this will not work. But when inserting a delay of 50 ms between InitUart() and the first "send" on UART it will work fine. See example from my code below.

 InitUart(radioUart, baud9600, &radioRxBuffer, &radioTxBuffer);
 
 // A small delay here seems to be necessary
 DelayMs(delayAfterBaudRateChange);
 
 // The radio should now be ready to communicate at speed 9600 Baud so a change to API mode is made
 ChangeFromTransparentToApiMode();

Best Regards

Bengt

0 项奖励
回复