当前位置:网站首页>2.2 STM32 GPIO operation

2.2 STM32 GPIO operation

2022-07-06 03:24:00 rou252051452

1、 summary

        By program PIN Device input , Output , Interruption, etc .

2、 Input

         

 3、 Output

 4、 interrupt

 

 4、 Test functions

/**
    1、 Output :
        1) Use the button of Polaris on the punctual atomic development board LED0(PB1) and LED1(PB0) As the output IO test .
        2) After the button is pressed ,LED0 bright 
        3) After the button is released ,LED0 destroy 
    2、 Input :
        1) Use the button of Polaris on the punctual atomic development board KEY0(PH3) Test as input 
        2) After the button is pressed ,LED0 bright 
        3) After the button is released ,LED0 destroy 
    3、 interrupt :
        1) Use the button of Polaris on the punctual atomic development board KEY1(PH2) As interrupt input 
        2) After the button is pressed ,LED1 bright 
        3) After the button is released ,LED1 destroy 
**/

#include "rtthread.h"
#include "board.h"

// The macro definition obtains the pin number .
#define LED0            GET_PIN(B,1)
#define LED1            GET_PIN(B,0)

static  rt_uint32_t     KEY0 = 0;
static  rt_uint32_t     KEY2 = 0;



void exti_callback()
{
    if(rt_pin_read(KEY2) == PIN_LOW)
    {
        rt_pin_write(LED1, PIN_LOW);
    }
    else
    {
        rt_pin_write(LED1, PIN_HIGH);
    }
}

void example_gpio()
{
    // adopt API Get pin number 
    KEY0 = rt_pin_get("PH.3");
    KEY2 = rt_pin_get("PC.13");

    // Set pin mode 
    rt_pin_mode(LED0, PIN_MODE_OUTPUT);
    rt_pin_mode(LED1, PIN_MODE_OUTPUT);
    rt_pin_mode(KEY0, PIN_MODE_INPUT_PULLUP);
    rt_pin_mode(KEY2, PIN_MODE_INPUT_PULLUP);

    // test LED Lamp output 
    for(rt_int8_t i = 0; i<5 ; i++)
    {
        rt_pin_write(LED0, PIN_LOW);
        rt_pin_write(LED1, PIN_LOW);
        rt_thread_delay(500);
        rt_pin_write(LED0, PIN_HIGH);
        rt_pin_write(LED1, PIN_HIGH);
        rt_thread_delay(500);
    }

    // Interrupt callback function binding 
    rt_pin_attach_irq(KEY2, PIN_IRQ_MODE_RISING_FALLING, exti_callback, RT_NULL);
    // Interrupt enable 
    rt_pin_irq_enable(KEY2, PIN_IRQ_ENABLE);

    while(1)
    {
        if(rt_pin_read(KEY0) == PIN_LOW)
        {
            rt_pin_write(LED0, PIN_LOW);
        }
        else
        {
            rt_pin_write(LED0, PIN_HIGH);
        }
        rt_thread_delay(200);
    }
}
MSH_CMD_EXPORT(example_gpio, example_gpio)

  Complete the project

GitHub - WangChief/RTT_H750_APP: In progress RTT Lower punctual atom STM32H750 Related development of

原网站

版权声明
本文为[rou252051452]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060319451932.html