Hi all,
I am trying to use MPC5606S UART interrupt function, but can not enter the interrupt service program.
It can not enter the interrupt function to send( void UART1_TransmitComplete(void)) and receive(void UART1_ReceiveComplete(void)) interrupt function, attachment is my project, please help me to see where the problem?
Here's my code:
#include "MPC5606S.h"
#include "IntcInterrupts.h"
int counterTX = 0;
int counterRX = 0;
char receiveBuffer[20];
void initModesAndClock(void) ;
void disableWatchdog(void);
void initPeriClkGen(void) ;
void UART1_Init(void);
void UART1_SendData(char data);
void UART1_TransmitComplete(void);
void UART1_ReceiveComplete(void);
void initModesAndClock(void)
{
//h04_GpioInit();
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=PLL0 */
ME.RUNPC[1].R = 0x00000010; /* Peri. Cfg. 1 settings: only run in RUN0 mode */
//ME.PCTL[32].R = 0x01; /* MPC56xxB/P/S ADC 0: select ME.RUNPC[1] */
ME.PCTL[68].R = 0x01; /* MPC56xxB/S SIU: select ME.RUNPC[1] */
ME.PCTL[49].R = 0x01; /* MPC56xxB/P/S FLEX1 : 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.GS.B.S_MTRANS) {} /* Wait for mode transition to complete */
/* Note: could wait here using timer and/or I_TC IRQ */
while(ME.GS.B.S_CURRENTMODE != 4) {} /* Verify RUN0 is the current mode */
}
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) */
}
void initPeriClkGen(void)
{
CGM.SC_DC[0].R = 0x80;
CGM.SC_DC[1].R = 0x80;
CGM.SC_DC[2].R = 0x80;
}
void UART1_Init(void)
{
volatile int i = 0;
LINFLEX_1.LINCR1.B.INIT = 1;
LINFLEX_1.LINCR1.B.SLEEP = 0;
LINFLEX_1.LINIBRR.R = 0x000001A0; //baud rate 9600b/s (fsys 64MHz)
LINFLEX_1.LINFBRR.R = 0x0000000B;
LINFLEX_1.UARTCR.B.UART = 1; //enable UART mode
LINFLEX_1.UARTCR.B.WL = 1; //set 8-bit data
LINFLEX_1.UARTCR.B.TXEN = 1; //enable transmitter
LINFLEX_1.UARTCR.B.TDFL = 0b00; //set transmitter buffer (1)
LINFLEX_1.LINIER.B.DTIE = 1; //Transmit interrupt enable
LINFLEX_1.UARTCR.B.RXEN = 1; //enable transmitter
LINFLEX_1.UARTCR.B.RDFL = 0b00; //set transmitter buffer (1)
LINFLEX_1.LINIER.B.DRIE = 1; //Receive interrupt enable
LINFLEX_1.LINCR1.B.INIT = 0; //disable init mode
for(i ; i < 5000; i++) //wait fo apply settings
{
}
}
void UART1_SendData(char data)
{
LINFLEX_1.BDRL.B.DATA0 = data; //send data
}
void UART1_TransmitComplete(void)
{
LINFLEX_1.UARTSR.R = 0x00000002; //clear interrupt flag
if(counterTX < 20) //check if less then 20 char was sent
{
UART1_SendData((char)counterTX); //send next data after received
counterTX++;
}
}
void UART1_ReceiveComplete(void)
{
LINFLEX_1.UARTSR.R = 0x00000004; //clear interrupt flag
receiveBuffer[counterRX] = LINFLEX_1.BDRM.B.DATA4; //copy received data to receiveBuffer
counterRX++;
}
int main(void) {
volatile int i = 0,j=0;
initModesAndClock(); /* Initialize mode entries and system clock */
disableWatchdog(); /* Disable watchdog */
initPeriClkGen(); /* Initialize peripheral clock generation for DSPIs */
UART1_Init();
SIU.PCR[29].R = 0x0600; //LIN1 TX
SIU.PCR[28].R = 0x0100; //LIN1 RX
INTC_InstallINTCInterruptHandler(UART1_ReceiveComplete,99,15);
INTC_InstallINTCInterruptHandler(UART1_TransmitComplete,100,14);
INTC.CPR.R = 0;
UART1_SendData((char)counterTX);
/* Loop forever */
while(1)
{
}
}
Original Attachment has been moved to: MPC5606S-UART_Interrupt.zip
Hello,
flash target works correct. If you want to use RAM target, you have to modify RAM_VLE.prefix in your project and recompile it. Please see figure below:
Regards,
Martin