STM32W108 Wireless RF module General I/O interface application example, stm32w108io

Source: Internet
Author: User

STM32W108 Wireless RF module General I/O interface application example, stm32w108io
STM32W108 radio frequency module General I/O interface application example

In this example, write the GPIO test program of javasw108, and control the LED lights by controlling the GPIO pins.

Development Environment and Hardware Description

Hardware: javasw108 Wireless Development Board, 5 V 1A power supply, J-Link writer, PC, etc.

Software: IAR Embedded Workbench for ARM development software.

Figure 6.15 shows the principle of hardware connection: LED1 is controlled through the GPIO pin PA3 of the megaw108 wireless module, and LED2 is controlled by the GPIO pin PC2.

 

Hardware planning:The control pins used are GPIO_PA3 and GPIO_PC2. When controlling the LED lights, you need to set the corresponding pins as output, and then control the output level through the output data register, in this way, the LED light is switched off.

6.3.2 software design and planning

In this example, the halSetLed () and halClearLed () functions are called to control the LED lights. This driver mainly describes how the compiler sets and applies the GPIO pin function. The function declaration format is as follows:

VoidHalSetLed (HalBoardLedled );

VoidhalClearLed (HalBoardLed );

6.3.3 LED Control Program Design

Compile the led driver source file led. c as follows:

/*************************************** *******************************

File Name: led. c

Main Function Description: halInitLed (void) function to implement LED initialization; halSetLed (HalBoardLed)

The function is used to set the LED to be bright. halClearLed (HalBoardLed) is used to set the led and disable it. halToggleLed (HalBoardLed) is used to set the LED to flash.

**************************************** ******************************/

# Include PLATFORM_HEADER

# Include BOARD_HEADER

# Include "hal/micro/led. h"

# Include "hal/micro/micro-common.h"

# Include "hal/micro/cortexm3/micro-common.h"

 

// Macro definition, PA-related registers

# Define GPIO_PxCLR_BASE (GPIO_PACLR_ADDR)

# Define GPIO_PxSET_BASE (GPIO_PASET_ADDR)

# Define GPIO_PxOUT_BASE (GPIO_PAOUT_ADDR)

 

// Register pin offset

# Define GPIO_Px_OFFSET (GPIO_PBCFGL_ADDR-GPIO_PACFGL_ADDR)

 

/*************************************** ***********************************

Function Description: initializes the LED.

Input parameter: None

Output parameter: None

**************************************** *********************************/

Void halInitLed (void)

{

// Configure the pins for LED1 and LED2

HalGpioConfig (LED_D1, GPIOCFG_OUT );

HalGpioConfig (LED_D2, GPIOCFG_OUT );

 

// Disable LED1 and LED2

HalClearLed (LED_D1 );

HalClearLed (LED_D2 );

}

 

/*************************************** ***********************************

Function Description: clears the corresponding port of the LED to enable it.

Input parameter: LED lamp ID, that is, the corresponding LED lamp Port

Output parameter: None

**************************************** *********************************/

Void halSetLed (HalBoardLed)

{

If (led/8 <3)

{

* (Volatile int32u *) (GPIO_PxCLR_BASE + (GPIO_Px_OFFSET * (led/8 ))))

= BIT (led & 7 );

}

}

 

/*************************************** ***********************************

Function Description: sets the port register value of the LED lamp to disable it.

Input parameter: LED lamp ID, that is, the corresponding LED lamp Port

Output parameter: None

**************************************** *********************************/

Void halClearLed (HalBoardLed)

{

If (led/8 <3)

{

* (Volatile int32u *) (GPIO_PxSET_BASE + (GPIO_Px_OFFSET * (led/8 ))))

= BIT (led & 7 );

}

}

 

/*************************************** ***********************************

Function Description: completes the setting of the LED light so that it is switched from the light to the light or from the light to the light.

Input parameter: led id, that is, the port corresponding to the LED

Output parameter: None

**************************************** *********************************/

Void halToggleLed (HalBoardLed)

{

// Atomic operation

ATOMIC (

If (led/8 <3)

{

* (Volatile int32u *) (GPIO_PxOUT_BASE + (GPIO_Px_OFFSET * (led/8 ))))

^ = BIT (led & 7 );

}

)

}

6.3.4 test program Compilation

Compile the test program source file main. c:

/*************************************** **************************

File Name: solar-system.c

Hardware Description: LED_D1 connects to PA3 and LED_D2 connects to PC2.

Main Function Description: The main () function controls io.

**************************************** *************************/

 

/*************************************** ***********************************

Function Description: completes the test of LED lights through io.

Input parameter: None

Output parameter: None

**************************************** *********************************/

Int main (void)

{

HalInit (); // initialize the hardware circuit

UartInit (115200, 8, PARITY_NONE, 1); // initialize UART serial port

// Configure PA4 and PA5 as the analog output function for packet tracking

HalGpioConfig (PORTA_PIN (4), gpio1__out_alt );

HalGpioConfig (PORTA_PIN (5), gpio1__out_alt );

GPIO_IRQDSEL = PORTB_PIN (2); // connect IRQD to master/SC1RXD

GPIO_INTCFGD = (3 <GPIO_INTMOD_BIT); // enable IRQD interruption

INT_GPIOFLAG = INT_IRQDFLAG;

INT_PENDCLR = INT_IRQD;

HalInitLed (); // initialize the LED light

 

While (TRUE) // infinite loop, so that the LED1 and LED2 lights flash at intervals of 1 s

{

HalSetLed (LED_D1); // light up LED1

HalClearLed (LED_D2); // disable LED2

HalCommonDelayMilliseconds (1000); // delay 1 s

HalClearLed (LED_D1); // disable LED1

HalSetLed (LED_D2); // light up LED2

HalCommonDelayMilliseconds (1000); // delay 1 s

}

}

6.3.5 Test Results and Analysis

After the program is compiled, the program is written to the javasw108 Wireless Development Board through J-link. Then, the program is executed. The test result is mainly verified by observing the light-off of the LED lamp ,. After the test program is executed, we can observe that LED1 and LED2 flash at intervals of 1 s to verify the correctness of the Instance program.

 

This article is written by Qiu tie, Xia Feng, and Zhou Yu, embedded wireless sensor network, w108, Tsinghua University Press, May 2014

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.