I am a student and we have a project to drive a Buzzer using an STM32. The professor will send frequencies to every one via Zigbee, we catch them and we drive the Buzzer, in order to have a complete symphony in the classroom composed of different instruments, each one is one of our boards that we have already developed. We are not allowed to use the STM32 firmware (only the STM32103XX_map.h file is allowed). Until now, I have configured the internal clocks, 2 buttons with interrupts, 3 leds, 1 LCD, the zigbee on UART3, but I'm blocked now on the buzzer part. I have to use a PWM on PA8 via TIM1_CH1 with a duty cicle of 50%. I have configured the registers as i think well, i mean enabling the clock, configuring the pins to work on alternative functions output, the prescalar, the autoreload, the mode (PWM2) the channel 1, and the capture compare, but still nothing is out of the buzzer. May someone tell me what are and in which order shall i configure those registers, in order to have a PWM signal with 50% duty cycle and a frequency range from 1K to 100khz, im changing ARR and TIM1->CCR each time so that CCR would be the half of TIM1->ARR, (i think also that i can play on the other way using TIM1->PSC in stead) I appreciate your help
I would appreciate if i find how to do it directly using registers because this is what I'm supposed to do tomorrow. But it is helpful, at least it gives me ideas about what to do before the other. Thank you so much again
Here is my code: RCC->APB2ENR |=0x00000800;//activate TIM1 clock //Initialize GPIO PA8 output AF 50Mhz GPIOA->CRH &=~0x0000000f; GPIOA->CRH |=0x0000000B;//mode alternate function //================================ TIM1->PSC=1;//le prescalar 63Mhz (72/(psc+1))=36Mhz TIM1->ARR=1799;//auto-reload (20 MHZ) TIM1->CCR1=900;//capture compare 50% duty cycle TIM1->CR1=0x0080;//Auto-reload preload enable TIM1->CCMR1=0x0078;//configuration of Capture/Compare PWM2 //Output Compare 1 preload enable TIM1->EGR |= 0x0001;//Update the registers TIM1->CR1 |=0x0001;//On activate timer 1 TIM1->CCER |=0x0001;//On activate chanel 1 If any one has an idea what might be the problem please tell me thanks