stm32w108Application example of external interrupt interface for wireless RF module
Write an interrupt service program, respond to external interrupts, implement a key trigger interrupt, and then display the corresponding status through the LED .
1stm32w108 Development environment and hardware description
Hardware:stm32w108 Zigbee Development Board,5V 1 A power supply,j-link burner,PC , etc.
Software:IAR Embedded Workbench development software.
For the key connection schematic in the Development Board, the key and the stm32w108 Wireless module connection schematic diagram.
Button Connection diagram
2Software Design and Planning
the flowchart of the test program is shown below , the node first initializes the hardware, then registers the interrupt, and then loops to detect whether the interrupt occurred. LED1 is lit in the interrupt handler function , When an external detected interrupt occurs, the delay is 1000ms, and then the LED1is closed, the process 7.11 is shown .
3Interrupt handler Design
The following drivers are written in solar-system.c :
/************************************************************************** Function Description: Interrupt handler, will flag position bit Input parameters: None Output parameters: None *************************************************************************/ void Halirqcisr () { Int_miss = INT_MISSIRQC;// Clear interrupt MISS int_gpioflag=int_irqcflag;// Resetting the int_irqcflag bit of the int_gpioflag Register preesed1 = true;// Press the key to the flag bit set to true halsetled (LED_D1);// light led_d1 } |
4Test program Writing
Write the test program source file solar-system.c:
/***************************************************************** File name:solar-system.c Hardware description:s2->pc0,led1->pa3 Main function Description: main() function to achieve LED1 lamp shutdown, when the S2 button is pressed and released, will trigger an interrupt, in the interrupt processing function to highlight the LED1 lamp, when the main () turn off the lit LED1When an interrupt is detected in the function. *****************************************************************/ #include Platform_header #include Board_header #include <stdio.h> #include <stdlib.h> #include <string.h> #include "Error.h" #include "hal/hal.h" #include "Include/phy-library.h" #include "Hal/micro/cortexm3/iap_bootloader.h" #include "Hal/micro/led.h" #include "Hal/micro/button.h" Boolean preesed1 = FALSE;// global variable indicating whether a button was pressed /************************************************************************** Function Description: Complete the flashing of LED lights through interrupt control Input parameters: None Output parameters: None *************************************************************************/ int main (void) { halinit ();// Initialize hardware circuit Uartinit (115200, 8, Parity_none, 1);// Configure UART serial port // Configure PA4 and PA5 for multiplexing output functions for packet tracking Halgpioconfig (Porta_pin (4), gpiocfg_out_alt); Halgpioconfig (Porta_pin (5), gpiocfg_out_alt); Gpio_irqdsel = Portb_pin (2);// connect irqd with pb2/sc1rxd // allow irqd interrupt GPIO_INTCFGD = (3<<gpio_intmod_bit); Int_gpioflag = Int_irqdflag; INT_PENDCLR = INT_IRQD; Interrupts_on (); halinitled ();// initialize LED lights Halgpioconfig (BUTTON_S2,GPIOCFG_IN_PUD);// configuration button_s2 GPIO_INTCFGC = 0; Clear 0 GPIO_INTCFGC Register int_cfgclr = INT_IRQC;// Clear irqc Interrupt Int_gpioflag = Int_irqcflag;// Clear irqc Interrupt Flag Int_miss = INT_MISSIRQC; clears the IRQC interrupt Miss Flag Gpio_irqcsel = button_s2;// IRQC pin corresponds to button_s2 pin GPIO_INTCFGC = (0 << gpio_intfilt_bit);// do not use digital filtering GPIO_INTCFGC |= (3 << gpio_intmod_bit);// rising edge and falling edge trigger int_cfgset = INT_IRQC;// enable IRQC Interrupt while (TRUE) { Halcommondelaymilliseconds (Ten);// delay 10ms If (preesed1 = = TRUE)// Determine if the button has been pressed, that is, to determine if there is an interruption occurred { Preesed1=false; set the flag bit to false halcommondelaymilliseconds (1000); Delay 1000ms halclearled (LED_D1);// close LED1 } } } |
5Test results and analysis
Burn the program into stm32w108 ZigBee Development Board, press the key on the Development Board S2 , at this time LED1 flashes once, and then remains off.
Interrupts are set to trigger on rising and falling edges, test method: First press the button, do not release, at this time LED1 will blink once, and then release the button, the LED1 will blink again, indicating that both the rising edge and the falling edge have triggered the interruption.
This article is from "stm32w108 embedded wireless sensor network" Tie Qiu, Xiafeng, newcomer authoring . Tsinghua University Press , year 5 months
STM32W108 Wireless RF Module External Interrupt Interface application Example