[k20d72m]: way to reset UART instance

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[k20d72m]: way to reset UART instance

Jump to solution
1,258 Views
huishao2
Contributor IV

Hi-

Is there a way to reset one of UART instances in K20d72m right away?

thanks and regards

Hui

Tags (4)
0 Kudos
1 Solution
857 Views
yasuhikokoumoto
Senior Contributor I

Hi Hui,


how about the following settings. Those are UART initialization after exiting from the low power mode which are described in the low power mode sample code for K20.

(1) Clock supply for the specified UART.

switch(uartch){
  case UART0_BASE_PTR: SIM_SCGC4 |= SIM_SCGC4_UART0_MASK; break;
  case UART1_BASE_PTR: SIM_SCGC4 |= SIM_SCGC4_UART1_MASK; break;
  case UART2_BASE_PTR: SIM_SCGC4 |= SIM_SCGC4_UART2_MASK; break;
  case UART3_BASE_PTR: SIM_SCGC4 |= SIM_SCGC4_UART3_MASK; break;
  case UART4_BASE_PTR: SIM_SCGC1 |= SIM_SCGC1_UART4_MASK; break;
  case UART5_BASE_PTR: SIM_SCGC1 |= SIM_SCGC1_UART5_MASK; break;
  }

(2) Disable Transmit and Receive to change the settings.

  UART_C2_REG(uartch) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);

(3) For example, setting for 8-bit and no parity.
   UART_C1_REG(uartch) = 0;

(4) Baud rate setting.
    sbr = (uint16)((sysclk*1000)/(baud * 16));

    temp = UART_BDH_REG(uartch) & ~(UART_BDH_SBR(0x1F));

    UART_BDH_REG(uartch) = temp |  UART_BDH_SBR(((sbr & 0x1F00) >> 8));
    UART_BDL_REG(uartch) = (uint8)(sbr & UART_BDL_SBR_MASK);
    brfa = (((sysclk*32000)/(baud * 16)) - (sbr * 32));

    temp = UART_C4_REG(uartch) & ~(UART_C4_BRFA(0x1F));

    UART_C4_REG(uartch) = temp |  UART_C4_BRFA(brfa);

                          
(5) Enable transmit and receive.

  UART_C2_REG(uartch) |= (UART_C2_TE_MASK | UART_C2_RE_MASK);

Best regards,

Yasuhiko Koumoyo.

View solution in original post

0 Kudos
7 Replies
857 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Hui,

   If the UART srewed up, you can clear your according register manually.

   You don't need to reset the whole UART independently.

Regards,

Jingjing

0 Kudos
857 Views
huishao2
Contributor IV

Thanks! I will give it a try.

Hui

0 Kudos
858 Views
yasuhikokoumoto
Senior Contributor I

Hi Hui,


how about the following settings. Those are UART initialization after exiting from the low power mode which are described in the low power mode sample code for K20.

(1) Clock supply for the specified UART.

switch(uartch){
  case UART0_BASE_PTR: SIM_SCGC4 |= SIM_SCGC4_UART0_MASK; break;
  case UART1_BASE_PTR: SIM_SCGC4 |= SIM_SCGC4_UART1_MASK; break;
  case UART2_BASE_PTR: SIM_SCGC4 |= SIM_SCGC4_UART2_MASK; break;
  case UART3_BASE_PTR: SIM_SCGC4 |= SIM_SCGC4_UART3_MASK; break;
  case UART4_BASE_PTR: SIM_SCGC1 |= SIM_SCGC1_UART4_MASK; break;
  case UART5_BASE_PTR: SIM_SCGC1 |= SIM_SCGC1_UART5_MASK; break;
  }

(2) Disable Transmit and Receive to change the settings.

  UART_C2_REG(uartch) &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK);

(3) For example, setting for 8-bit and no parity.
   UART_C1_REG(uartch) = 0;

(4) Baud rate setting.
    sbr = (uint16)((sysclk*1000)/(baud * 16));

    temp = UART_BDH_REG(uartch) & ~(UART_BDH_SBR(0x1F));

    UART_BDH_REG(uartch) = temp |  UART_BDH_SBR(((sbr & 0x1F00) >> 8));
    UART_BDL_REG(uartch) = (uint8)(sbr & UART_BDL_SBR_MASK);
    brfa = (((sysclk*32000)/(baud * 16)) - (sbr * 32));

    temp = UART_C4_REG(uartch) & ~(UART_C4_BRFA(0x1F));

    UART_C4_REG(uartch) = temp |  UART_C4_BRFA(brfa);

                          
(5) Enable transmit and receive.

  UART_C2_REG(uartch) |= (UART_C2_TE_MASK | UART_C2_RE_MASK);

Best regards,

Yasuhiko Koumoyo.

0 Kudos
856 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Hui Shao,

      I don't know why you want to reset UART module independently.

      All register of UART is reset only when the MCU is reset.

     Actually, you don't need to reset all the register independently, if needed, you can use the soft code to reset the according register.

Wish it helps you!

-----------------------------------------------------------------------------------------------------------------------

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

-----------------------------------------------------------------------------------------------------------------------

0 Kudos
857 Views
huishao2
Contributor IV

Hi Jingjing

I just wanted to bring UART back to known state in case it is srewed up.

Thanks!

Hui

0 Kudos
857 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Hui Shao,

      Chould you tell me more detail about your demand?

    Do you want to reset all the register of UART in K20D72M?

    If yes, you can use the chip software reset, the code is :

  #define Reset()      (SCB_AIRCR = SCB_AIRCR_VECTKEY(0x5FA)|SCB_AIRCR_SYSRESETREQ_MASK)

  Wish it helps you!
  If you still have question, please let me know!


Have a great day,
Jingjing

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

0 Kudos
857 Views
huishao2
Contributor IV

Hi Jingjing

Reset done through AIRCR seems to be causing a system reset. What is needed is a reset on all registers/state machine inside one UART only. During the reset, the ARM processor keeps running as usual.

Thanks!

Hui

0 Kudos