yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0G3507 Development Board📖
1. Introduction to MSPM0
  • 1. Introduction to MSPM0
2. Development environment construction
  • 01.CCS Theia Development
  • 02.MDK Arm Development
  • 03.UniFlash Downloader
  • 04.DAP-LINK download program
  • 05.Program simulation and debugging
  • 06.Engineering transplantation
3. Keil basic case
  • 1. Turn on the LED light
  • 2. System delay
  • 3. Button control
  • 4. External interruption
  • 5. Serial communication
  • 6. Timer
  • 7. PWM breathing light
  • 8. ADC acquisition
  • 9. DMA transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
4. CCS basic case
  • 1. Turn on the LED light
  • 2. System delay
  • 3. Button control
  • 4. External interruption
  • 5. Serial communication
  • 6. Timer
  • 7. PWM breathing light
  • 8. ADC acquisition
  • 9. DMA transfer
  • 10. Get MPU6050 data (I2C)
  • 11. LCD Display (SPI)
5. MSPM0 Robot Expansion Board
  • 1. MSPM0 Robot Expansion Board Introduction
  • 2. Custom Buttons
  • 3. Drive Buzzer
6.MSPM0-K230 Vision Application Module
  • 1.k230 color recognition
  • 2.k230 barcode recognition
  • 3.k230 QR code recognition
  • 4.k230Apriltag code recognition
  • 5.k230DM code recognition
  • 6.k230 face detection
  • 7.k230 gaze direction
  • 8.k230 face recognition
  • 9.k230 human body detection
  • 10.k230 fall detection
  • 11.k230 palm detection
  • 12.k230 gesture recognition
  • 13.k230OCR character recognition
  • 14.k230 object detection
  • 15.k230 target tracking
  • 16.k230 self-learning object recognition
  • 17.k230 license plate recognition
7. MSPM0-K210Vision module application
  • 0.Prerequisites for K210 as a coprocessor
  • 1.MSPM0_K210 color recognition
  • 2.MSPM0_K210 barcode recognition
  • 3.MSPM0_K210 QR code recognition
  • 4.MSPM0_K210 mechanical code recognition
  • 5.MSPM0_K210 face detection
  • 6.MSPM0_K210 facial feature detection
  • 7.MSPM0_K210 mask detection
  • 8.MSPM0_K210 face recognition
  • 9.MSPM0_K210 Object Detection
  • 10.MSPM0_K210 Self-study classification
  • 11.MSPM0_K210 handwritten digit recognition
8. Expansion casenew
  • 1.Autonomous driving car
  • 2.Vehicle-mounted balance ball motion control system
Download
  • Code
  • Hareware_Info
  • Software_Tools
  • Communication Protocol
Download ZIP

Welcome to MSPM0G3507 Development Board repository

2. Custom Buttons

Custom Buttons

1. Hardware Connection

This case uses the MSPM0 Robot Expansion Board. The peripherals used do not require additional wiring. Simply insert the Yahboom MSPM0G3507 core board into the expansion board.

2. Code Explanation

  • empty.c
int main(void)
{
    USART_Init();
    
    //清除定时器中断标志 Clear timer interrupt flag
    NVIC_ClearPendingIRQ(TIMER_0_INST_INT_IRQN);
    //使能定时器中断   Enable Timer Interrupt
    NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN);
    //定时器开始计时   Timer start
    DL_TimerA_startCounter(TIMER_0_INST);
    
    while (1)
    {
        //按键检测设置在<timer.c>中 
        //Keystroke detection settings in <timer.c>
    }
}

The main function performs system initialization and timer startup. This project places key detection in the <timer.c> file.

 

  • timer.c
​x
void TIMER_0_INST_IRQHandler(void)
{
    switch( DL_TimerG_getPendingInterrupt(TIMER_0_INST) )
    {
        case DL_TIMER_IIDX_ZERO://如果是0溢出中断  If it is a 0 overflow interrupt
            Key_Handle();//按键触发检测   Key Trigger Detection
            systick_counter++; // 每1ms自动+1      +1 per sencond
            break;
​
        default:
            break;
    }
    
}
​
uint32_t Get_Time(void)    
{
    return systick_counter;
}
  • TIMER_0_INST_IRQHandler: 1ms timer interrupt function, used for continuously detecting key input and also for counting
  • Get_Time: Used to get the total count

 

  • key.c
xxxxxxxxxx
// 定义按键句柄 - Define key handle
Key_t key1 = {
    .GPIOx = KEY_PORT,
    .GPIO_Pin = KEY_K1_PIN,
    .state = KEY_STATE_RELEASED,
    .pressTime = 0,
    .debounceTime = 0
};
​
​
/* 消抖时间(单位:ms) - Debounce time (ms) */
#define DEBOUNCE_DELAY 20  // 典型值:10-50ms / Typical value: 10-50ms
​
/**
 * @brief 按键扫描函数(非阻塞式) - Key scan function (non-blocking)
 * @param key         按键句柄指针 / Pointer to KeyHandle
 * @param currentTime 当前系统时间(单位:ms) / Current system time (ms)
 * @param longPressThreshold 长按时间阈值(单位:ms) / Long press threshold (ms)
 * @return KeyEvent   返回按键事件 / Returns key event
 */
KeyEvent Key_Scan(Key_t* key, uint32_t currentTime, uint32_t longPressThreshold) {
    // 读取按键电平:0表示按下,1表示释放 / Read pin level: 0=pressed, 1=released
    uint8_t isPressed = 0;
    
    if(DL_GPIO_readPins(key->GPIOx, key->GPIO_Pin) == 0)
    {
        isPressed = 1;
    }
    
    switch (key->state) {
        /* 状态1:按键释放 - State 1: Key released */
        case KEY_STATE_RELEASED:
            if (isPressed) {
                key->state = KEY_STATE_DEBOUNCE;       // 进入消抖状态 / Enter debounce state
                key->debounceTime = currentTime;      // 记录消抖开始时间 / Record debounce start time
            }
            break;
​
        /* 状态2:消抖检测 - State 2: Debounce checking */
        case KEY_STATE_DEBOUNCE:
            // 消抖时间到达后检测稳定状态 / Check stable state after debounce delay
            if (currentTime - key->debounceTime >= DEBOUNCE_DELAY) {
                if (isPressed) {
                    key->state = KEY_STATE_PRESSED;    // 确认按下 / Confirm press
                    key->pressTime = currentTime;      // 记录按下时间 / Record press time
                } else {
                    key->state = KEY_STATE_RELEASED;   // 抖动误触发 / False trigger due to bounce
                }
            }
            break;
​
        /* 状态3:已按下 - State 3: Pressed */
        case KEY_STATE_PRESSED:
            if (!isPressed) {
                key->state = KEY_STATE_RELEASED;       // 释放触发短按 / Release triggers short press
                return KEY_EVENT_SHORT;                // 返回短按事件 / Return short press event
            } else if (currentTime - key->pressTime >= longPressThreshold) {
                key->state = KEY_STATE_LONG;           // 触发长按 / Trigger long press
                return KEY_EVENT_LONG;                 // 返回长按事件 / Return long press event
            }
            break;
​
        /* 状态4:长按已触发 - State 4: Long press triggered */
        case KEY_STATE_LONG:
            if (!isPressed) {
                key->state = KEY_STATE_RELEASED;       // 释放后重置状态 / Reset state after release
            }
            break;
    }
​
    return KEY_EVENT_NONE;  // 默认无事件 / Default: no event
}
​
void Key_Handle(void)
{
    int16_t LongPressThreshold = 700;// 按键扫描时长按的阈值:500ms    Threshold for long press during key scanning: 500ms
    static uint32_t lastTick = 0;  // 初始时间  initial time
    uint32_t currentTick = Get_Time();
    static int task_flag = 1;
​
    // 每10ms检测一次按键 - Check key every 10ms
    if (currentTick - lastTick >= 10) {
        lastTick = currentTick;
​
        KeyEvent event = Key_Scan(&key1, currentTick, LongPressThreshold);
​
        switch (event) {
            case KEY_EVENT_SHORT:
                // 处理短按 Handle short press
//                printf("short press\r\n");
                LED_Toggle();
                break;
            case KEY_EVENT_LONG:
                // 处理长按 Handle long press
                
                break;
            default:
                break;
        }
    }
}
​
  • Key_t key1: Create a key structure to store the configuration of the key's pin and press duration.
  • Key_Scan: By obtaining the timer count, determine the key press time, used for debouncing and determining whether it's a long press or short press.
  • Key_Handle: Key detection processing function, can change the long press threshold of the key to make long press trigger faster or slower. In the switch judgment event, different functions can also be triggered according to short press or long press. Here, the short press event is processed by toggling the LED level.

 

  • led.c
xxxxxxxxxx
void LED_Toggle(void)
{
    DL_GPIO_togglePins(LED_PORT, LED_D1_PIN);
}
  • LED_Toggle: LED level toggle, if the light is off, pressing the key will toggle it to on.

 

3. Program Phenomenon

After burning the program and pressing the NRST key to reset, you can press the K1 button on the expansion board to turn on or off the LED light with D1 silkscreen on the core board.

MSPM0 Robot Expansion Board Introduction
Drive Buzzer

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文