2011-12-29 12:37 PM
I have a MCBSTM32 board which uses the STM32F107 and includes a CS42L52 audio CODEC chip on board. I'm trying to create a 12 MHz clock input for the CODEC using TIM3 from the STM32. So far I have succeeded in generating the required 12MHz clock, but I'm not sure if it will work for the CODEC. The CODEC will accept smaller clock values (8KHz etc...) but I figured it was easier to only have to worry about one clock vs. several clocks.
I have attached screenshots of the output and wanted to get some feedback, as they don't look very pretty. My thoughts are that I'm simply approaching the upper limits of the STM's clocking ability. As I understand it the 72MHz is simply multiplied from the real clock @ 25 MHz? In my code the system clock is set for 72MHz. Below is the timer setup code:int main(void)
{ RCC->APB2ENR |= RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN; RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; GPIOC->CRL = 0x0b000000; // Enable pin 6 @ 50mhz AFIO->MAPR = AFIO_MAPR_TIM3_REMAP; // Remap TIM3 pins to PC6, 7, 8 and 9 TIM3->PSC = 2; // Set prescaler to 2 (PSC + 1 = 3; SYSCLK(72MHz) / 3 = 12 MHz) TIM3->ARR = 1; // Auto reload value TIM3->CCR1 = 1; // Start PWM duty for channel 1 TIM3->CCMR1 = TIM_CCMR1_OC1M; TIM3->CCER = TIM_CCER_CC1E; // Enable compare on channel 1 TIM3->CR1 = TIM_CR1_CEN; // Start timer //TIM3->DIER = TIM_DIER_UIE; // Enable update interrupt (timer level) //NVIC_EnableIRQ(TIM3_IRQn); // Enable interrupt from TIM3 (NVIC level) while (1) {} } #stm32f107-codec-clock-tim32011-12-29 06:12 PM
That does look pretty awful, like the loading is quite high. Try looking at another channel, not connected to the codec.
Personally I'd recommend using a PSC=0 for such a high output rate. (ARR=5, CCR=3) Want to confirm the quality of the internal clock(s), export via the MCO pin.2011-12-29 08:06 PM
Exactly correct in regards to the loading, had the probes set for 1x vs 10x! I did change the PSC like you recommended as well, seemed to be a little more stable than the settings I was using originally. Now I can finally to get to work on the codec part.
Thanks for the assist. Regards, Tim2011-12-30 12:17 PM
Finally was able to get the CS42L52 working this morning. I've only messed around with the beep generator, but I figured that would be the easiest proof of concept and then I can go from there.
For those who have the same board or the same codec, here is what I have for initialization code. This code assumes that there is a 12MHz clock input to the MCLK of the codec. I'm using TIM3 to generate the clock. After the codec is initialized, I added a few lines of code to enable the beep generator in continuous mode. If you go through the documentation it will mention various settings that are required, for the beep generator you only need three lines to init the codec, power it down, master/slave set to master, power it up. And actually the first power down is not required because it powers down by default after it powers up, confusing eh? Questions/comments welcomed. -Tim// Init CODEC
I2C_putbyte(0x94, 0x02, 0x01); // Power down to configure (powered down by default, but good to have)
I2C_putbyte(0x94, 0x06, 0x80); // Master/Slave set to master (required) I2C_putbyte(0x94, 0x0F, 0x0A); // Set speaker to mono and let Spkr B=A (not required) I2C_putbyte(0x94, 0x20, 0xC0); // Master Volume CH A (not required) I2C_putbyte(0x94, 0x04, 0xAA); // Ignore speaker/headphone jumper setting (not required) I2C_putbyte(0x94, 0x02, 0x00); // Power down up after initial configure (required) // Make beep I2C_putbyte(0x94, 0x1C, 0x70); // Beep on time & Freq // Beep on time ignored in continuous mode I2C_putbyte(0x94, 0x1D, 0x02); // Beep Off time & Vol // Beep off time ignored in continuous mode I2C_putbyte(0x94, 0x1E, 0xC0); // Activate beep continuous beep mode