5.13 OPAMP Guide

This chapter describes the file composition and the 10 public functions of the OPAMP driver in the N32G033 standard peripheral library, together with the 1 PGA example. Read the four operating modes, gain steps and input pin mapping of the internal op-amp together with the “Operational amplifier (OPAMP)” chapter of the user manual; for known silicon issues, refer to the errata sheet.

5.13.1 Related files

Relative path Purpose
firmware/n32g033_std_periph_driver/inc/n32g033_opamp.h Defines the OPAMP_InitType structure and the macros for operating mode, gain, VP/VM input selection, reference voltage and lock, and declares the 10 public functions in four sections: reset and init, internal buffer and gain, input selection and lock, reference voltage
firmware/n32g033_std_periph_driver/src/n32g033_opamp.c Implements the 10 functions above: OPAMP reset, structure defaults and init, enable and internal buffer, gain and input selection, reference voltage selection and lock
projects/n32g033_EVAL/examples/OPAMP/ OPAMP example root directory, containing 1 example: PGA
projects/n32g033_EVAL/examples/OPAMP/PGA/ Example directory composition: MDK-ARM/, EWARM/, inc/, src/, readme.txt

5.13.2 API reference

Search API10 functions

The 10 public functions below are grouped into 4 groups in the declaration order of n32g033_opamp.h; each entry gives a function summary and the source comment verbatim above that function in n32g033_opamp.c.

Reset and init

OPAMP_DeInit, OPAMP_StructInit, OPAMP_Init, OPAMP_Enable

Internal buffer and gain

OPAMP_EnableInterBufferMode, OPAMP_SetPgaGain

Input selection and lock

OPAMP1_SetVpSel, OPAMP1_SetVmSel, OPAMP_SetLock

Reference voltage selection

OPAMP_VREFPSel

void OPAMP_DeInit(void)Reset the OPAMP registers.
Source comment
name    OPAMP_DeInit.
fun     Reset the OPAMP registers.
return  none
void OPAMP_StructInit(OPAMP_InitType* OPAMP_InitStruct)Fills each OPAMP_initstruct member with its default value.
Source comment
name    OPAMP_StructInit.
fun     Fills each OPAMP_initstruct member with its default value.
param   OPAMP_initstruct :
          - Gain
          - Mode
          - OPAMP1_Vpsel
          - OPAMP1_Vmsel
return  none
void OPAMP_Init(OPAMPX OPAMPx, OPAMP_InitType* OPAMP_InitStruct)Initializes the OPAMP according to OPAMP_InitStruct.
Source comment
name    OPAMP_Init.
fun     Initializes the OPAMP according to OPAMP_InitStruct.
param   OPAMPX :
          - OPAMP1
          - OPAMP2
          - OPAMP3
param   OPAMP_InitStruct :
          - Mode :just vailed For OPAMP1
            - OPAMP1_CS_MODE_EXT_OPA
            - OPAMP1_CS_MODE_DIFF_PGA
            - OPAMP1_CS_MODE_INTER_PGA
            - OPAMP1_CS_MODE_BUFF_EN
          - Mode :just vailed For OPAMP2/3
            - OPAMP23_CS_MODE_DISBALE
            - OPAMP23_CS_MODE_BUFF_EN
param     - VpSel : just vailed For OPA1
            - OPAMP1_CS_VPSEL_PF0
            - OPAMP1_CS_VPSEL_PA0
            - OPAMP1_CS_VPSEL_PA1
            - OPAMP1_CS_VPSEL_PA4
            - OPAMP1_CS_VPSEL_PA7
            - OPAMP1_CS_VPSEL_PB0
          - VmSel : just vailed For OPA1
            - OPAMP1_CS_VMSEL_PF1
            - OPAMP1_CS_VMSEL_PA2
            - OPAMP1_CS_VMSEL_PA5
            - OPAMP1_CS_VMSEL_PB1
            - OPAMP1_CS_VMSEL_PB2
          - Gain : just vailed For OPAMP1
            - OPAMP1_CS_PGA_GAIN_2_DIFF_1
            - OPAMP1_CS_PGA_GAIN_4_DIFF_2
            - OPAMP1_CS_PGA_GAIN_8_DIFF_4
            - OPAMP1_CS_PGA_GAIN_16_DIFF_8
            - OPAMP1_CS_PGA_GAIN_32_DIFF_16
            - OPAMP1_CS_PGA_GAIN_xx_DIFF_32
          - Gain : just vailed For OPAMP2/3
            - OPAMP23_CS_PGA_GAIN_DIFF_1
            - OPAMP23_CS_PGA_GAIN_DIFF_2
            - OPAMP23_CS_PGA_GAIN_DIFF_4
            - OPAMP23_CS_PGA_GAIN_DIFF_8
            - OPAMP23_CS_PGA_GAIN_DIFF_16
return  none
void OPAMP_Enable(OPAMPX OPAMPx, FunctionalState Cmd)Enable or disable opampx .
Source comment
name    OPAMP_Enable.
fun     Enable or disable opampx .
param   OPAMPX :
          - OPAMP1
          - OPAMP2
          - OPAMP3
param   Cmd :
          - ENABLE
          - DISABLE
return  none
void OPAMP_EnableInterBufferMode(OPAMPX OPAMPx, FunctionalState Cmd)Enable or disable opampx internal buffer mode .
Source comment
name    OPAMP_EnableInterBufferMode.
fun     Enable or disable opampx internal buffer mode .
param   OPAMPX :
          - OPAMP2
          - OPAMP3
param   Cmd :
          - ENABLE
          - DISABLE
return  none
note  OPA2 and OPA3 support this function.
void OPAMP_SetPgaGain(OPAMPX OPAMPx, uint32_t Gain)Set opampx gain value selection
Source comment
name    OPAMP_SetPgaGain.
fun     Set opampx gain value selection
param   OPAMPX :
          - OPAMP1
          - OPAMP2
          - OPAMP3
param   Gain :
        - OPAMP1
          - OPAMP1_CS_PGA_GAIN_2_DIFF_1
          - OPAMP1_CS_PGA_GAIN_4_DIFF_2
          - OPAMP1_CS_PGA_GAIN_8_DIFF_4
          - OPAMP1_CS_PGA_GAIN_16_DIFF_8
          - OPAMP1_CS_PGA_GAIN_32_DIFF_16
          - OPAMP1_CS_PGA_GAIN_xx_DIFF_32
        - OPAMP2/3
          - OPAMP23_CS_PGA_GAIN_DIFF_1
          - OPAMP23_CS_PGA_GAIN_DIFF_2
          - OPAMP23_CS_PGA_GAIN_DIFF_4
          - OPAMP23_CS_PGA_GAIN_DIFF_8
          - OPAMP23_CS_PGA_GAIN_DIFF_16
return  none
void OPAMP1_SetVpSel(uint32_t VpSel)Set opamp1 VP selection
Source comment
name    OPAMP1_SetVpSel.
fun     Set opamp1 VP selection
param   VpSel :
          - OPAMP1_CS_VPSEL_PF0
          - OPAMP1_CS_VPSEL_PA0
          - OPAMP1_CS_VPSEL_PA1
          - OPAMP1_CS_VPSEL_PA4
          - OPAMP1_CS_VPSEL_PA7
          - OPAMP1_CS_VPSEL_PB0
return  none
void OPAMP1_SetVmSel(uint32_t VmSel)Set opamp1 Vm selection
Source comment
name    OPAMP1_SetVmSel.
fun     Set opamp1 Vm selection
param   VmSel :
          - OPAMP1_CS_VMSEL_PF1
          - OPAMP1_CS_VMSEL_PA2
          - OPAMP1_CS_VMSEL_PA5
          - OPAMP1_CS_VMSEL_PB1
          - OPAMP1_CS_VMSEL_PB2
return  none
void OPAMP_SetLock(uint32_t Lock)Set opamp lock
Source comment
name    OPAMP_SetLock.
fun     Set opamp lock
param   Lock :
          - OPAMP_LOCK
return  none
void OPAMP_VREFPSel(OPAMPX OPAMPx, uint32_t VrefSel)Set opampx vrefp selection
Source comment
name    OPAMP_VREFPSel.
fun     Set opampx vrefp selection
param   OPAMPX :
          - OPAMP1
          - OPAMP2
          - OPAMP3
param   VrefSel :
          - OPAMP_VREFP_SEL_0_9V
          - OPAMP_VREFP_SEL_1_8VDD
          - OPAMP_VREFP_SEL_1_4VDD
return  none

5.13.3 Demo descriptions

This section describes the 1 OPAMP example: PGA configures OPAMP1 in internal PGA mode to amplify the non-inverting input on PA0 by 2, and outputs the result on PA6.

5.13.3.1 PGA internal PGA gain amplification

Example directory: projects/n32g033_EVAL/examples/OPAMP/PGA/

Enable GPIO and OPA clocks→configure PA0 and PA6 as analog→configure OPAMP1 in internal PGA mode with 2x gain through the structure→enable OPAMP1 and output the amplified result on PA6

Item Source analysis
Function Configure OPAMP1 in internal PGA mode, with PA0 as the non-inverting input and PA6 as the output, to amplify the input voltage by 2.
Source files src/main.c contains RCC_Configuration, GPIO_Configuration, OPAMP_Configuration;
src/n32g033_it.c and inc/n32g033_it.h provide the interrupt functions;
inc/main.h gives the declarations;
readme.txt gives the configuration and test steps;
project files are in MDK-ARM/ and EWARM/.
Key configuration Pins: PA0 is the OPA1 non-inverting input, PA6 is the OPA1 output, both as analog function;
mode: OPAMP1_CS_MODE_INTER_PGA (internal PGA);
gain: OPAMP1_CS_PGA_GAIN_2_DIFF_1 (2x);
clock: system clock 64 MHz.
Program and data path main -> RCC_Configuration enables the GPIO and OPA clocks -> GPIO_Configuration sets PA0 and PA6 to analog -> OPAMP_Configuration takes the defaults and fills mode, input and gain, then calls OPAMP_Init and OPAMP_Enable -> the amplified result is output on PA6.
Main APIs OPAMP_StructInit, OPAMP_Init, OPAMP_Enable
Verification Build and enter debug mode, then observe the PA0 input and the PA6 output with an oscilloscope;
the OPA1 output is about 2 times the input voltage.
Use note The development environment is KEIL MDK-ARM V5.34.0.0 or IAR EWARM 8.50.1;
the internal PGA gain comes from the on-chip resistor feedback network, so the input must stay within the supply range.
Core-code walkthrough and porting

The example writes the OPAMP1 input, operating mode and gain into the structure in one pass; after init, enabling it produces the output.

Data path: RCC_Configuration enables the GPIO and OPA clocks -> GPIO_Configuration writes PA0 and PA6 analog mode -> OPAMP_StructInit takes the defaults -> OPAMP_Configuration fills the input and the internal PGA gain -> OPAMP_Init writes the control registers -> OPAMP_Enable enables the output

1. First enable the APB clocks of GPIO and OPA. OPA is on the APB bus, so both clocks are enabled in one pass before the pins and the op-amp can be configured.

src/main.csrc/main.c · RCC_Configuration
void RCC_Configuration(void)
{
    /* Enable peripheral clocks ------------------------------------------------*/

    /* Enable GPIO OPA clocks */
    RCC_EnableAPBPeriphClk(RCC_APB_PERIPH_GPIO | RCC_APB_PERIPH_OPA, ENABLE);
}

For another module, change RCC_APB_PERIPH_xxx as needed; several macros in the same statement can be ORed together.

2. Configure the input and output pins as analog function. In analog mode the pins are disconnected from the digital channel; the input PA0 and the output PA6 share one configuration.

src/main.csrc/main.c · GPIO_Configuration
    GPIO_InitStruct(&GPIO_InitStructure);
    /* Configure  INP PA0 OUT PA6 as analog input -----------------------*/
    GPIO_InitStructure.Pin       = GPIO_PIN_0 | GPIO_PIN_6;
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_ANALOG;
    GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);

When using other input or output pins, change Pin here accordingly and make sure the pin numbers follow the OPA input/output mapping in the user manual.

3. Configure mode, input and gain in one structure, then enable. The structure members correspond to the operating mode, the non-inverting input selection and the gain; this example selects internal PGA mode with 2x gain and finally enables OPAMP1.

src/main.csrc/main.c · OPAMP_Configuration
    OPAMP_InitType OPAMP_Initial;
    OPAMP_StructInit(&OPAMP_Initial);
    OPAMP_Initial.OPAMP1_Vpsel = OPAMP1_CS_VPSEL_PA0;
    OPAMP_Initial.Gain         = OPAMP1_CS_PGA_GAIN_2_DIFF_1;
    OPAMP_Initial.Mode         = OPAMP1_CS_MODE_INTER_PGA;
    /*configure opamp1*/
    OPAMP_Init(OPAMP1, &OPAMP_Initial);

    OPAMP_Enable(OPAMP1, ENABLE);

In single-ended PGA mode the VM pin must stay floating and the gain step must match the mode; when switching to follower or differential mode, change both the Mode and Gain macros as specified in the user manual.

Corresponding source files: src/main.c, firmware/n32g033_std_periph_driver/inc/n32g033_opamp.h

5.13.4 Notes and troubleshooting

Scenario Check & action Source
Input and output range The OPAMP chapter of the user manual states that the OPAMP input range is 0 V to VDDA and the output range is 0.4 V to VDDA-0.4 V;
when the signal exceeds this range the output is unusable.
User manual
VM pin in single-ended PGA The OPAMP chapter of the user manual states that in single-ended gain (PGA) mode (MOD=10) the VMSEL pin must be set floating;
the VP pin selects the non-inverting input.
User manual
VM pin in follower mode The OPAMP chapter of the user manual states that in follower mode VMSEL is connected internally to the output port;
an unused VM pin can serve as a normal GPIO.
User manual
Gain step matching the mode The OPAMP chapter of the user manual states that the OPA1 single-ended PGA gain is 2/4/8/16/32 and the differential PGA gain is 1/2/4/8/16/32;
OPA2 and OPA3 support differential PGA only, with gains of 1/2/4/8/16, and have no output pin.
User manual
OPAMP write protection The OPAMP chapter of the user manual states that once OPAMP_LOCK is set the OPAMP1/2/3 control registers become read-only;
only a chip reset or an OPA module reset clears the write protection.
User manual

Errata sheet V1.0.0 (2025.9.25) covers revision A silicon and lists no OPAMP entries.

Nations Technologies DevKit Docs

Datasheets, SDK, driver APIs and demo guides for Nations Technologies MCU development kits, organized by chip series.

© 2026 Nations Technologies Inc. All rights reserved.粤ICP备11069485号This site uses cookie-free anonymous analytics.