Welcome to MSPM0G3507 Development Board repository
3. Drive Buzzer
Drive Buzzer
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(); PWM_Buzzer_Init(); while (1) { Buzzer_Toggle(); delay_ms(1000); }}- PWM_Buzzer_Init: Start PWM timer, used to drive the buzzer.
- Buzzer_Toggle: Buzzer on/off toggle, set here to beep for one second, then stop for one second.
- buzzer.c
xvoid PWM_Buzzer_Init(void) { DL_Timer_startCounter(BUZZER_INST);}void Buzzer_Toggle(void){ static int i=0; if(i==0) { Buzzer_ON(); i=1; } else { Buzzer_OFF(); i=0; }}void Buzzer_ON(void){ DL_TimerA_setCaptureCompareValue(BUZZER_INST, 30, GPIO_BUZZER_C3_IDX);}void Buzzer_OFF(void){ DL_TimerA_setCaptureCompareValue(BUZZER_INST, 0, GPIO_BUZZER_C3_IDX);}- Buzzer_ON: Adjust the buzzer volume by setting a certain PWM duty cycle
- Buzzer_OFF: Set the PWM duty cycle to 0, the buzzer will not sound
3. Program Phenomenon
After burning the program and pressing the NRST key to reset, you can hear the buzzer on the expansion board beep for one second, then stop for one second, repeating this pattern.