It has been a few days since I received the NXP FREEDOM DEVELOPMENT BOARD KW41Z. I really want to experience this board. I have a connection with it. As early as 2015, when I attended an offline seminar of NXP, I had the honor to see this development board. At that time, it was mainly promoted with Thread, and some demo examples were made for its demonstration. Although the concept of the Internet of Things was very popular at that time, the Internet of Things technology was still relatively weak. There was no Bluetooth mesh in the wireless networking. The most popular ones at that time were Zigbee of CC2530 and Lora of SX1278.
Therefore, when I saw the presenter demonstrating Thread networking and future Thread applications, I felt that this was a new direction and a new way of IoT networking. Of course, Thread doesn’t seem to be promoted much now, but I still remembered my original intention. I took this opportunity to have a good time with KW41Z, and it really got what I wanted.
The protagonist of this event is KW41Z, a low-power Bluetooth and 802.15.4 wireless communication solution launched by NXP Semiconductors. It integrates an ARM Cortex-M0+ processor and multiple wireless communication protocols, including Bluetooth Low Energy and IEEE 802.15.4. KW41Z is suitable for IoT devices, smart homes, sensor networks and other fields, with low power consumption, high performance and rich peripheral interfaces. It also supports NXP's Thread and Zigbee protocol stacks, providing more choices and flexibility for IoT applications.
After getting the development board, of course you need to build the environment and turn on the lights. The official actually provides some SDKs, which include IAR and MCUXpressoIDE projects and middleware, and support Keil, but it is recommended to build the Keil environment yourself, so this time I will use the IAR environment to implement the environment application and lighting operations.
IAR version 8.32 is selected this time, and the basic program project uses SDK_2_2_3_FRDM-KW41Z\boards\frdmkw41z\driver_examples\gpio in the SDK. This is what it looks like after opening the project.
Based on the structure in the routine, you can know what each part of the program does, where the initialization is, and what the initialization structure is. This time, since we only run through the environment and drive the LED, we only need to know how to drive the high and low levels of IO.
First, initialize the IO. In this program, since we want to drive a three-color LED, we need to drive three IOs, namely PC1, PA18 and PA19.
void BOARD_InitPins(void) {
CLOCK_EnableClock(kCLOCK_PortA); /* Port A Clock Gate Control: Clock enabled */
CLOCK_EnableClock(kCLOCK_PortC); /* Port C Clock Gate Control: Clock enabled */
PORT_SetPinMux(PORTA, PIN18_IDX, kPORT_MuxAsGpio); /* PORTA18 (pin 6) is configured as PTA18 */
PORT_SetPinMux(PORTA, PIN19_IDX, kPORT_MuxAsGpio); /* PORTA19 (pin 7) is configured as PTA19 */
PORT_SetPinMux(PORTC, PIN1_IDX, kPORT_MuxAsGpio); /* PORTC1 (pin 37) is configured as PTC1 */
PORT_SetPinMux(PORTC, PIN6_IDX, kPORT_MuxAlt4); /* PORTC6 (pin 42) is configured as UART0_RX */
PORT_SetPinMux(PORTC, PIN7_IDX, kPORT_MuxAlt4); /* PORTC7 (pin 43) is configured as UART0_TX */
SIM->SOPT5 = ((SIM->SOPT5 &
(~(SIM_SOPT5_LPUART0RXSRC_MASK))) /* Mask bits to zero which are setting */
| SIM_SOPT5_LPUART0RXSRC(SOPT5_LPUART0RXSRC_LPUART_RX) /* LPUART0 Receive Data Source Select: LPUART_RX pin */
);
}
Next, configure the IO mode, that is, configure the IO output.
/* Init output LED GPIO. */
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &led_config);
GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, &led_config);
GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, &led_config);
The next step is to implement the control of IO, such as outputting high level or outputting low level. This time, the IO inversion mode is adopted, that is, toggle, so the code is as follows:
delay();
delay();
GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1u << BOARD_LED_GPIO_PIN);
delay();
delay();
GPIO_TogglePinsOutput(BOARD_LED_GREEN_GPIO, 1u << BOARD_LED_GREEN_GPIO_PIN);
delay();
delay();
GPIO_TogglePinsOutput(BOARD_LED_BLUE_GPIO, 1u << BOARD_LED_BLUE_GPIO_PIN);
The final effect is as follows:
In fact, after this simple lighting operation, I think this KW41Z is relatively easy to use, mainly because the official routines are relatively clear. Next, I will drive the sensor based on the routines, so stay tuned~