UART interrupt wake up without loosing data

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

UART interrupt wake up without loosing data

2,139 Views
paljano
Contributor II

Hello,

I have a MK10DX128 VLH7 Microcontroller. The controller operates mostly in sleep mode. Now Im trying to kommunicate with my microcontroller. Sending data from the controller to the host works fine. But If I try to send data from host to my controller it dont work.

I use the interrupt wake up from rising edge on UART module. It wakes up, receive the first character without a problem but behind the first one it received only garbage.

Example:

I sendet "Hello".

And this is received:

HY????

My question is: Is there a possibility to receive data without loosing information when I use the transmitted datastream to wake up the controller?

My irq for the rising edge:

void UART_Status_irq()

{

    if(UART0_S2        &    UART_S2_RXEDGIF_MASK){                        // Rising edge interrupt

        UART0_S2        |=    UART_S2_RXEDGIF_MASK;                    // Clear interrupt flag

            int i=0;

            // Read command

            for(i=0;temp!='\r';i++)

            {

                while(!(UART0_S1 & UART_S1_RDRF_MASK));

                UART_Receiver[i]        =    UART0_D;

                temp=UART_Receiver[i];

            }

     }

}

My UART initialisation:

void UART_init(unsigned int baud,unsigned int uartclk_khz)                              // Initialise UART0

{

      Uint16 sbr,brfa;

      //Initialisation

      SIM_SCGC4         |=    SIM_SCGC4_UART0_MASK;                                     // Activate clock for UART

      SIM_SCGC5         |=    SIM_SCGC5_PORTB_MASK;                                     // Activate clock for PortC

      PORTB_PCR16       =     PORT_PCR_MUX(3);                                          // Set PortB 16 for UARC

      PORTB_PCR17       =     PORT_PCR_MUX(3);                                          // Set PortB 17 for UARC

           

      sbr               =     (Uint16)((uartclk_khz*1000)/(baud*16));

      UART0_BDH         =     (Uint8)((sbr & 0x1F00)>>8);                               // Write high word of baud rate into register

      UART0_BDL         =     (Uint8)(sbr & 0x00FF);                                    // Write low word of baud rate into register

     

      brfa              =     (((uartclk_khz*32000)/(baud*16))-(sbr*32));

      UART0_C4          =     (Uint8)(brfa & 0x001F);                                   // Write divider into register  

      UART0_C1          =     0;                                                        // 8-Bit-Mode,No parity

     

      UART0_PFIFO       |=    UART_PFIFO_TXFE_MASK                                      // Enable transmitter FIFO

                        |     UART_PFIFO_RXFE_MASK                                      // Enable receiver FIFO

                        |     UART_PFIFO_TXFIFOSIZE(2)                                  // Transmitter FIFO depth = 8 elements

                        |     UART_PFIFO_RXFIFOSIZE(2);                                 // Receiver FIFO depth = 8 elements

     

      UART0_BDH         |=    UART_BDH_RXEDGIE_MASK;                                    // Enable interrupts from an edge on RxD

      enable_irq(45);                                                                   // Enable interrupts from UART module

      NVICIP45          =     0x10;                                                     // Set Priority 1 to the UART module

     

      UART0_C2          |=    (UART_C2_TE_MASK | UART_C2_RE_MASK );                     // Enable receiver and transmitter

}


It would be nice when you can help me.

regards,

Eric


Labels (1)
0 Kudos
5 Replies

1,055 Views
karthikbandi
Contributor I

Hello,

I want to use MK10DN64 as it supports TSI all channels to wake up MCU from VLPS low power mode as i want to use both TSI all channels and one UART to wake up the MCU from low power mode.

For this i want to configure the MCU in VLPS mode and use UART Rx pin as an interrupt and wake up the MCU from VLPS mode to RUN mode.

How can i configure MCU in VLPS mode (with/without using PE) and use UART to wake up the MCU and which UART do i need to configure as there no specific low power UARTs.

Thanks,

0 Kudos

1,055 Views
mjbcswitzerland
Specialist V

Hi

Get the uTasker open source project from http://www.utasker.com/kinetis.html
and open the file kinetis_low_power.h
It contains everything you need to do what you want (for UART and/or LPUART) so just cut and paste a few relevant lines to your environment (eg. entering VLPS mode with UART wakeup enabled, recovering from VLPS mode after UART wakeup).

Regards

Mark

0 Kudos

1,055 Views
mjbcswitzerland
Specialist V

Eric

You haven't specified which sleep mode you use. If basic sleep (WAIT) the periphertals don't stop so there should be no problems. In STOP mode you can also keep the PLL operating so that clock recovery is not needed. In VLPS there are a number of factors depending on which clocks are used.

See the following: Using Kinetis Low Power Stop Modes with unrestricted UART operation - a report

Also make sure that you are not returning to certain sleep based modes "before" reception has completed because this will corrupt data.

Regards

Mark

0 Kudos

1,055 Views
paljano
Contributor II

Hello Mark,

thank you for your answer. Im using an external oscillator with 32kHz to create my clocksource with FLL 48MHz.

My systemclock init:

void main_clock_init()

{

    //MCG_C1        |=    MCG_C1_IREFS_MASK;

    MCG_C4        |=    MCG_C4_DMX32_MASK

                          |    MCG_C4_DRST_DRS(1);

}

For going in stop mode I use the following initialisation:

//Energy management

    SMC_PMPROT    |=    SMC_PMPROT_AVLP_MASK;

    SMC_PMCTRL    &=    ~SMC_PMCTRL_STOPM_MASK;

    SMC_PMCTRL    |=     SMC_PMCTRL_STOPM(0);

And the command to enter the stop mode:

void enter_stopmode()   // Enter stop mode

{

    volatile unsigned int dummyread;

    dummyread = SMC_PMCTRL;

    SCB_SCR    |=    SCB_SCR_SLEEPDEEP_MASK;

    asm("WFI");

}

Can be there any problems because of that configuration?

I think that is not the normal stopmode because of the SMC_PMPROT_AVLP_MASK. The Clock is deactivated in that mode?

Thank you for your help.

0 Kudos

1,055 Views
mjbcswitzerland
Specialist V

Eric

I think that this is normal STOP mode (SMC_PMPROT_AVLP_MASK is setting the protection and not controlling the mode, which is defined by SMC_PMCTRL).

Whether the external oscillator is disabled or not in the STOP mode depends on the setting of EREFSTEN in OSCx_CR.

Regards

Mark

0 Kudos