AnsweredAssumed Answered

LINFlex Initialization

Question asked by Bengt Andersson on Oct 31, 2016
Latest reply on Nov 3, 2016 by Bengt Andersson

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

Outcomes