🛠 GPIO Control and Analog Sensor Reading on HPM5100
Objectives
This tutorial aims to master human-machine interaction and environmental perception on the HPM5100 board. You will learn to configure GPIO ports to control a simple display and utilize the integrated 16-bit SAR Analog-to-Digital Converters (ADCs) to read an analog sensor. The challenge is understanding how the 400 MHz RISC-V core handles critical I/O without excessive latency, leveraging the powerful mixed-signal peripherals of this chip.
Required Hardware
- HPM5100 Development Board (SDK version 1.13.0+)
- A simple analog sensor (e.g., potentiometer or LDR)
- An LED or small OLED display (via SPI or GPIO)
- Connection cables (Dupont)
- PC with HPMicro SDK compatible development tool
Steps
- Environment Setup : Ensure your HPMicro SDK is up to date. Open your IDE or text editor and create a new project based on the
hello_worldexample to ensure correct linking with the RISC-V compilation chain.
- GPIO Initialization : In your source code, include necessary headers (
hpm_gpio.h). Configure the pin connected to the LED as a push-pull output. For the display, if using SPI, enable the corresponding SPI peripheral via Pin Multiplexer (PinMux). The HPM5100 offers great pin routing flexibility; check the datasheet to confirm alternative functions.
- SAR ADC Configuration : The HPM5100 has four 16-bit SAR ADCs. Select the ADC connected to your sensor. Configure the trigger mode (software or timer) and number of samples. The 16-bit resolution provides high precision for fine detection.
- Reading and Processing Loop : In the main loop, start an ADC conversion. Wait for conversion completion via interrupt flags or polling. Read the raw value (0 to 65535 for 16 bits).
- Output Control : Map the read value to LED intensity (if PWM is available on this pin) or display the value on the screen. Use internal operational amplifiers (PGA) if the sensor signal is too weak for direct ADC input.
Verification
Open the serial monitor or observe the display. Turn the potentiometer or change the LDR lighting. The displayed value should vary linearly between minimum and maximum values. The LED should react proportionally. Verify the absence of excessive noise thanks to 16-bit resolution.
Further Reading
Explore using DMA to transfer ADC data to SRAM without CPU intervention, freeing the RISC-V core for other critical tasks like CAN FD communication.