yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
MSPM0G3519 Development Board📖
1. Introduction to MSPM0
  • 1. Introduction to MSPM0
2. Development environment construction
  • 1. CCS Theia Development
  • 2. MDK Arm Development
  • 3. UniFlash Downloader
  • 4. DAP-LINK download program
  • 5. Program Simulation and Debugging
  • 6. 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-K230Vision module application
  • 1. K230 Color Recognition
  • 2. K230 Barcode Recognition
  • 3. K230 QR Code Recognition
  • 4. K230 Apriltag Code Recognition
  • 5. K230 DM 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. K230 OCR 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. K210 Prerequisites For Making A Coprocessor - Must-see
  • 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 case
  • 1. Autonomous Driving Car
  • 2. Vehicle-mounted Balance Ball Motion Control System
Download
  • Code
  • Hardware_Info
  • Software_Tools
Download ZIP

Welcome to MSPM0G3519 Development Board repository

2. Custom Buttons

Custom Buttons

1. Hardware Wiring

This case uses the MSPM0 Robot Expansion Board. The peripherals used do not require additional wiring. You only need to insert the Yahboom MSPM0G3519 core board into the expansion board.

2. Code Explanation

  • empty.c

​x
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)
    {
        // Keystroke detection settings in <timer.c>
    }
}

The main function executes system initialization and timer enable. In this project, key detection is placed in the <timer.c> file.

 

  • timer.c

xxxxxxxxxx
void TIMER_0_INST_IRQHandler(void)
{
    switch( DL_TimerG_getPendingInterrupt(TIMER_0_INST) )
    {
        case DL_TIMER_IIDX_ZERO:// If it is a 0 overflow interrupt
            Key_Handle();// Key Trigger Detection
            systick_counter++; // +1 per second
            break;

        default:
            break;
    }

}

uint32_t Get_Time(void)
{
    return systick_counter;
}
  • TIMER_0_INST_IRQHandler: 1ms timer interrupt function, used for continuous key input detection and counting

  • Get_Time: Used to get 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
};


/* Debounce time (ms) */
#define DEBOUNCE_DELAY 20  // Typical value: 10-50ms

/**
 * @brief Key scan function (non-blocking)
 * @param key         Pointer to KeyHandle
 * @param currentTime Current system time (ms)
 * @param longPressThreshold Long press threshold (ms)
 * @return KeyEvent   Returns key event
 */
KeyEvent Key_Scan(Key_t* key, uint32_t currentTime, uint32_t longPressThreshold) {
    // 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) {
        /* 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;

        /* 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;

        /* 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;

        /* 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;// 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;

    // 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 configured key pin and press duration.

  • Key_Scan: Judge the key press duration by getting the timer count, used for debouncing and determining long press or short press.

  • Key_Handle: Key detection processing function. You can change the long press threshold to make long press trigger faster or slower. In the switch event judgment, you can also trigger different functions based on short press or long press. Here, the short press event handles LED level toggle.

 

  • 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, press the NRST key to reset. Then you can press the K1 key on the expansion board to light up or turn off the D1 labeled LED 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/中文