AnsweredAssumed Answered

MPC5604P UART Interrupt

Question asked by Xuuu rraa on Mar 21, 2017
Latest reply on Jan 25, 2018 by Martin Kovar

Hi, I am looking how to configure a receive interrupt in MPC5604P. I wanna an interrupt each data recepcion.

 

This is part of my code:

 

void UART_ReceiveComplete()
{
LINFLEX_0.UARTSR.R = 0x00000004; //clear interrupt flag

Toggle_LedErr();

/* wait until Slave response to the LIN header has been receive successfully */

while(0 == LINFLEX_0.LINSR.B.DRF) {} /* track LIN Status for errors */
receiveBuffer[0] = LINFLEX_0.BDRL.B.DATA0; //copy received data to receiveBuffer
receiveBuffer[1] = LINFLEX_0.BDRL.B.DATA1; //copy received data to receiveBuffer
receiveBuffer[2] = LINFLEX_0.BDRL.B.DATA2; //copy received data to receiveBuffer
receiveBuffer[3] = LINFLEX_0.BDRL.B.DATA3; //copy received data to receiveBuffer
receiveBuffer[4] = LINFLEX_0.BDRM.B.DATA4; //copy received data to receiveBuffer
receiveBuffer[5] = LINFLEX_0.BDRM.B.DATA5; //copy received data to receiveBuffer
receiveBuffer[6] = LINFLEX_0.BDRM.B.DATA6; //copy received data to receiveBuffer
receiveBuffer[7] = LINFLEX_0.BDRM.B.DATA7; //copy received data to receiveBuffer

counterRX++;
/* clear RMB, HRF, DRF and DTF flags */
LINFLEX_0.LINSR.R = 0x0207;
}

 

static void init_LinFLEX_0_UART (void)
{
// config LINLFEX

/* enter INIT mode */
LINFLEX_0.LINCR1.R = 0x0081; /* SLEEP=0, INIT=1 */

/* wait for the INIT mode */
while (0x1000 != (LINFLEX_0.LINSR.R & 0xF000)) {}

/* configure pads */
SIU.PCR[18].R = 0x0604; /* Configure pad PB2 for AF1 func: LIN0TX */
SIU.PCR[19].R = 0x0100; /* Configure pad PB3 for LIN0RX */

LINFLEX_0.UARTCR.R = 0x0001; /* set the UART bit first to be able to write the other bits */

LINFLEX_0.UARTCR.R = 0x0033; /* 8bit data, no parity, Tx and Rx enabled, UART mode */
/* Transmit buffer size = 1 (TDFL = 0 */
/* Receive buffer size = 1 (RDFL = 0) */

LINFLEX_0.UARTSR.B.SZF = 1; // clear SZF flag
LINFLEX_0.UARTSR.B.DRF = 1; // clear data reception completed flag

/* configure baudrate 9600 */
LINFLEX_0.LINIBRR.R = 416; // 9600 Baud
LINFLEX_0.LINFBRR.R = 11; //(Registres en p.679 de "MPC5604P Microcontroller Reference Manual" Rev.4m
//Table 22-1. "Error calculation for programmed baud rates")
/* enter NORMAL mode */
LINFLEX_0.LINCR1.R = 0x0080; // INIT=0
LINFLEX_0.LINIER.B.DRIE = 1; //Receive interrupt enable 
}

 

int main(void)
{
volatile int i = 0;
uint8_t dummy = 0;
//int32_t dummy2;

 

/* INITIALITATIONS */
SYSTEM_Initialize();
Set_LedErr();
INTC_InstallINTCInterruptHandler(UART_ReceiveComplete,79,5); //Read UART Interrupt

Clr_LedErr();
Set_LedAlim();

RS485_Receive(); //RS-485 in mode Receive

/* Loop forever */
for (;;)
{

   //dummy2 = Read_UART();
   //for(i=0;i<3200000;i++){} // Wait 500 ms
   //Send_UART(dummy); // Send 8 bits data
   dummy++;
   //dummy2 = ReceiveData(dummy3);
}
}

 

Thanks.

Outcomes