UART0 interrupt problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

UART0 interrupt problem

ソリューションへジャンプ
1,754件の閲覧回数
mridulpandey
Contributor II

Hi all,
I was trying to program on KL02 microcontroller in keil-mdk using baremetal examples. I am finding trouble in using UART0 interrupt routines. I have written the following code for the initialization of UART interrupt as my UART buffer receives a character. Where am i going wrong?

void uart0_init (UART0_MemMapPtr uartch, int uart0clk, int baud)

{

    register uint16 sbr;

    uint8 temp;

   

    SIM_SCGC4 |= SIM_SCGC4_UART0_MASK;

   

    /* Make sure that the transmitter and receiver are disabled while we

     * change settings.

     */

    UART0_C2_REG(uartch) &= ~(UART0_C2_TE_MASK

  | UART0_C2_RE_MASK );

  UART0_C2_REG(uartch)  |= 0x20; // enabled Receiver Interrupt Enable for RDRF

      /* Configure the uart for 8-bit mode, no parity */

    UART0_C1_REG(uartch) = 0; /* We need all default settings, so entire register is cleared */

   

      /* Calculate baud settings */

    temp = UART0_C4;

    temp = (temp & UART0_C4_OSR_MASK) + 1;

    sbr = (uint16)((uart0clk)/(baud * (temp)));

   

       

    /* Save off the current value of the uartx_BDH except for the SBR field */

    temp = UART0_BDH_REG(uartch) & ~(UART0_BDH_SBR(0x1F));

  

    UART0_BDH_REG(uartch) = temp |  UART0_BDH_SBR(((sbr & 0x1F00) >> 8));

    UART0_BDL_REG(uartch) = (uint8)(sbr & UART0_BDL_SBR_MASK);

    /* Enable receiver and transmitter */

    UART0_C2_REG(uartch) |= (UART0_C2_TE_MASK

               | UART0_C2_RE_MASK );

   

}

Please Help...

ラベル(1)
タグ(2)
1 解決策
1,176件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mridul Pandey,

      Your initial code didn't enable the receive interrupt enable bit UART0_C2[RIE]. If you want get the receive interrupt, you should configure these points:

1. enable UART0_C2[RIE]  bit :

UART0_C2 |= UART0_C2_RIE_MASK;

2 . you should configure the NVIC for interrupt mode of UART0 operation:

enable_irq(12);

3. Enable the global interrupt:

EnableInterrupts;

4.  Add interrupt service function:

void UART0_IRQHandler(void)

{

  if (UART0_S1&UART_S1_RDRF_MASK)  // receive data

  {

      c = UART0_D;

  }

}

Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

元の投稿で解決策を見る

3 返答(返信)
1,176件の閲覧回数
mridulpandey
Contributor II

I want to get an interrupt as soon as i receive a character in UART0. Please help me with the initialization or the Service routine.

1,177件の閲覧回数
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mridul Pandey,

      Your initial code didn't enable the receive interrupt enable bit UART0_C2[RIE]. If you want get the receive interrupt, you should configure these points:

1. enable UART0_C2[RIE]  bit :

UART0_C2 |= UART0_C2_RIE_MASK;

2 . you should configure the NVIC for interrupt mode of UART0 operation:

enable_irq(12);

3. Enable the global interrupt:

EnableInterrupts;

4.  Add interrupt service function:

void UART0_IRQHandler(void)

{

  if (UART0_S1&UART_S1_RDRF_MASK)  // receive data

  {

      c = UART0_D;

  }

}

Wish it helps you!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,176件の閲覧回数
mridulpandey
Contributor II

Thanks Jingjing,

It was a great help and a nice learing, i am getting the interrupts but the controller gets reset by the reset handler.

Please help me solve this issue.

0 件の賞賛
返信