MKE04Z128VQH4 DEEP SLEEP MODE

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

MKE04Z128VQH4 DEEP SLEEP MODE

1,082 Views
evren_kenanoglu
Contributor I

Dear Sir or Madam,

I'm working on MKE04Z128VQH4 microcontroller. My plan is that putting microcontroller deepsleep mode and wake it up via Uart Interrupt.

   I managed to put it deepsleep mode with this code:(or maybe I thought I could)  

void DeepSleep()
{
SCB->SCR |=  SCB_SCR_SLEEPDEEP_Msk;
SCB->SCR |=  SCB_SCR_SEVONPEND_Msk ; // wake up with any interrupt

uint32_t SLEEPONEXIT_Mask = ~(SCB_SCR_SLEEPONEXIT_Msk);
SCB->SCR &= SLEEPONEXIT_Mask;
__WFI();

}

But I couldn't wake it up. 

After that, I have noticed that in the Functional Block Diagram Picture WIC(Wakeup Interrupt Controller) is an optional component and asked your online support service. She said that "it seems in this MKE04Z128VQH4 we don't have but ask the community."

Here are my first questions:

1) Does the MKE04Z128VQH4 have the WIC module?

if(Answer=="No") 

1.1) In this pdf https://www.nxp.com/docs/en/data-sheet/MKE04P80M48SF0.pdf it includes MKE04Z128VQH4(R), it says STOP() mode exists. How can we wake up in STOP(DeepSleep) mode?

if(Answer=="Yes)

1.2) How can we wake up the processor without WIC in DEEPSLEEP mode? 

2) Could we wake up any serial communication interrupt(Uart, SPI...)?

3) Could you provide me MKE04Z128VQH4(R) modules datasheet? Cause I couldn't find it?

I'm sorry it's an emergency, hope you answer me quickly!

Best Regards.

Labels (1)
0 Kudos
2 Replies

949 Views
evren_kenanoglu
Contributor I

Hey Jing Pan,

Thank you for your help, In this case I had experience something like that: If you try to call DeepSleep() function in UART interrupt (IRQ Handler), I experienced that microcontroller can not wake up, so I put in somewhere else where I can control in a while loop and call DeepSleep() function. It's been such a great experience for me.

Here is the code: ( I recommend you to open this code with VSCODE. Sorry for lots of pragma regions :/) 

void DEMO_UART_IRQHandler(void)
{
#pragma region DATA RECEIVING
uint8_t data;

/* If new data arrived. */
if ((kUART_RxDataRegFullFlag | kUART_RxOverrunFlag) & UART_GetStatusFlags(DEMO_UART))
{

data = UART_ReadByte(DEMO_UART);
demoBuffer[rxIndex] = data;
rxIndex++;

if (data == END_BYTE_OF_MESSAGE) // '\r' ascii code
{
rxIndex = 0;
bufferReceivedStatus = COMPLETED;

charArrayClear(charArrayControl);
intArrayReset(bufferArray);
int length = strlen(demoBuffer) - 2;
for (int i = 0; i <= length; i++)
{
charArrayControl[i] = demoBuffer[i];
}
for (int i = 0; i <= length + 1; i++)
{
bufferArray[i] = demoBuffer[i];
}
}
}


#pragma endregion
#pragma region CONTROLS

if (bufferReceivedStatus == COMPLETED)
{
if (strcmp(charArrayControl, "LED1ON") == 0)
{
GPIO_PinWrite(BOARD_INITPINS_LED1_GPIO_PORT, BOARD_INITPINS_LED1_PIN, 1);
}

if (strcmp(charArrayControl, "LED1OFF") == 0)
{
GPIO_PinWrite(BOARD_INITPINS_LED1_GPIO_PORT, BOARD_INITPINS_LED1_PIN, 0);
}

if (strcmp(charArrayControl, "LED2ON") == 0)
{
GPIO_PinWrite(BOARD_INITPINS_LED2_GPIO_PORT, BOARD_INITPINS_LED2_PIN, 1);
}
if (strcmp(charArrayControl, "LED2OFF") == 0)
{
GPIO_PinWrite(BOARD_INITPINS_LED2_GPIO_PORT, BOARD_INITPINS_LED2_PIN, 0);
}
if (strcmp(charArrayControl, "DS") == 0)
{
enterSleep = 1; // At the first I call here deepsleep function but now just checking here if DS string has come or not!
}

charArrayClear(demoBuffer);
}


/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif

#pragma endregion
}

int main(void)
{

#pragma region INITIALS PINS, CLOCKS, PERIPHERALS...
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitBootPeripherals();

#pragma endregion

#pragma region UART CONFIGS
/*
* config.baudRate_Bps = 115200U;
* config.parityMode = kUART_ParityDisabled;
* config.stopBitCount = kUART_OneStopBit;
* config.txFifoWatermark = 0;
* config.rxFifoWatermark = 1;
* config.enableTx = false;
* config.enableRx = false;
*/
uart_config_t config;
UART_GetDefaultConfig(&config);
config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
config.enableTx = true;
config.enableRx = true;

UART_Init(DEMO_UART, &config, DEMO_UART_CLK_FREQ);

/* Send g_tipString out. */
UART_WriteBlocking(DEMO_UART, g_tipString, sizeof(g_tipString) / sizeof(g_tipString[0]));

/* Enable RX interrupt. */
UART_EnableInterrupts(DEMO_UART, kUART_RxDataRegFullInterruptEnable | kUART_RxOverrunInterruptEnable | kUART_RxActiveEdgeInterruptEnable );

EnableIRQ(DEMO_UART_IRQn);
#pragma endregion

while (1)
{
/* Send data only when UART TX register is empty and ring buffer has data to send out. */
while ((kUART_TxDataRegEmptyFlag & UART_GetStatusFlags(DEMO_UART) && bufferReceivedStatus))
{
UART_WriteByte(DEMO_UART, bufferArray[txIndex]);

txIndex++;

if (bufferArray[txIndex] == END_BYTE_OF_MESSAGE)
{
bufferReceivedStatus = RESET;
txIndex = 0;
break;
}
}

if (enterSleep)
{
GPIO_PinWrite(BOARD_INITPINS_LED2_GPIO_PORT, BOARD_INITPINS_LED2_PIN, 1);
DeepSleep();  // HERE DEEP SLEEP
GPIO_PinWrite(BOARD_INITPINS_LED2_GPIO_PORT, BOARD_INITPINS_LED2_PIN, 0);
enterSleep = 0;
}

}

}

0 Kudos

949 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Envren,

1. Yes, KE0x has WIC. You can search AWIC in reference manual.

1.2 Please see table 3-11 in RM. It shows different wake-up source.

3. Please download datasheet from Arm Cortex-M0+|Kinetis KE04 48 MHz 32-bit 5V MCUs | NXP . It's name is MKE04P80M48SF0

I made a demo to show you wake-up by uart. It seems that with uart interrupt enable, you needn't set anything. The demo will enter deepsleep mode after initialize. When you input a word in uart terminal, it will abort deepsleep and print "out of deepsleep".

Regards,

Jing

0 Kudos