I have tried to implement some of the code posted for MPC5604P, but not work. Then I tried to configure only the recieve interruption, but still not working.
I´m using new codeWarrior, version 10.5.
This is my last code:
#include "MPC5604P.h"
#include "IntcInterrupts.h"
int counterTX = 0;
int counterRX = 0;
char receiveBuffer[20];
/*------------------------Funció InitCMU_0----------------------------------------------------
* Es configura el Clock Monitor Unit per a complir l'especificacio:
* Monitor FXOSC>FIRC/4 (4Mhz); withou FMPLL monitor
* FXOSC=8Mhz i FIRC=
*
* 16Mhz;
* (Registres en p.112 de "MPC5604P Microcontroller Reference Manual" Rev.4)
--------------------------------------------------------------------------------------------*/
void InitCMU_0(void)
{
CGM.CMU_0_CSR.R = 0x00000004;
}
/*------------------------Funció InitModesAndClks-------------------------------------------*
* S'habiliten els modes DRUN, RUN0, SAFE i RESET.
* El rellotge del sistema és del tipus FMPLL, aconseguint 64Mz a partir d'un cristall de 8MHz
* Es configuren els periferics per treballar en el mode RUN0
* (Registres en p.141 de "MPC5604P Microcontroller Reference Manual" Rev.4)
* => Mode Entry Module (ME)
* (Registres en p.120 de "MPC5604P Microcontroller Reference Manual" Rev.4)
* => Clock Generation Module (CGM)
--------------------------------------------------------------------------------------------*/
void InitModesAndClks(void)
{
ME.MER.R = 0x0000001D; // Enable DRUN, RUN0, SAFE, RESET modes
// Initialize PLL before turning it on:
CGM.FMPLL[0].CR.R = 0x02400100; // 8 MHz xtal: Set PLL0 to 64 MHz
ME.RUN[0].R = 0x001F0074; // RUN0 cfg: 16MHzIRCON,OSC0ON,PLL0ON,syclk=PLL
ME.RUNPC[0].R = 0x00000010; // Peri. Cfg. 0 settings: only run in RUN0 mode
ME.RUNPC[1].R = 0x00000010; /* Peri. Cfg. 1 settings: only run in RUN0 mode */
ME.PCTL[16].R = 0x0000; // FlexCAN0: select ME.RUNPC[0]
ME.PCTL[4].R = 0x0000; // DSPI0: select ME.RUNPC[0]
ME.PCTL[32].R = 0x01; // ADC 0: select ME.RUNPC[1] ??????????
// Mode Transition to enter RUN0 mode:
ME.MCTL.R = 0x40005AF0; // Enter RUN0 Mode & Key
ME.MCTL.R = 0x4000A50F; // Enter RUN0 Mode & Inverted Key
while (ME.IS.B.I_MTC != 1) {} // Wait for mode transition to complete
ME.IS.R = 0x00000001; // Clear Transition flag
}
/*------------------------Funció DisableWatchdog----------------------------------------------
* (Registres en p.954 de "MPC5604P Microcontroller Reference Manual" Rev.4)
--------------------------------------------------------------------------------------------*/
void DisableWatchdog(void)
{
SWT.SR.R = 0x0000c520; // Write keys to clear soft lock bit
SWT.SR.R = 0x0000d928;
SWT.CR.R = 0x8000010A; // Clear watchdog enable (WEN)
}
/*------------------------- initPeroClckGen Function-----------------------------------------
*
------------------------------------------------------------------------------------------*/
void initPeriClkGen(void) {
CGM.AC2SC.R = 0x04000000; /* MPC56xxP Safety Port: Select PLL0 for aux clk 0 */
CGM.AC2DC.R = 0x80000000; /* MPC56xxP Safety Port: Enable aux clk 0 div by 1 */
CGM.AC0SC.R = 0x04000000; /* MPC56xxP ADC: Select PLL0 for aux clk 0 */
CGM.AC0DC.R = 0x80000000; /* MPC56xxP ADC: Enable aux clk 0 div by 1 */
}
void LIN0_Init()
{
volatile int i = 0;
LINFLEX_0.LINCR1.B.INIT = 1;
LINFLEX_0.LINCR1.B.SLEEP = 0;
LINFLEX_0.LINIBRR.R = 0x000001A0; //baud rate 9600b/s (fsys 64MHz)
LINFLEX_0.LINFBRR.R = 0x0000000B;
LINFLEX_0.UARTCR.B.UART = 1; //enable UART mode
LINFLEX_0.UARTCR.B.WL = 1; //set 8-bit data
LINFLEX_0.UARTCR.B.RXEN = 1; //enable transmitter
LINFLEX_0.UARTCR.B.RDFL = 0b00; //set transmitter buffer (1)
LINFLEX_0.LINIER.B.DRIE = 1; //Receive interrupt enable
LINFLEX_0.LINCR1.B.INIT = 0; //disable init mode
for(i ; i < 5000; i++){} //wait fo apply settings
}
void LIN0_ReceiveComplete()
{
LINFLEX_0.UARTSR.R = 0x00000004; //clear interrupt flag
receiveBuffer[counterRX] = (char)LINFLEX_0.BDRM.B.DATA4; //copy received data to receiveBuffer
counterRX++;
}
int main(void)
{
volatile int dummy = 0;
InitCMU_0(); // 8 MHz OSC requires non-default CMU_0 init
InitModesAndClks(); // Initialize mode entries
DisableWatchdog(); // Disable watchdog
initPeriClkGen();
LIN0_Init();
//SIU.PCR[19].R = 0x0100; //LIN0 RX B3
SIU.PCR[23].R = 0x0100; //LIN0 RX B7
INTC_InstallINTCInterruptHandler(LIN0_ReceiveComplete,79,5);
INTC.CPR.R = 0;
/* Loop forever */
for (;;)
{
dummy++;
counterRX=counterRX; //To see counterRX when debugg
}
}