Skip to main content
uprogc
Associate II
July 22, 2013
Question

STM32F4Discovery - I2S config

  • July 22, 2013
  • 6 replies
  • 1099 views
Posted on July 22, 2013 at 18:28

Hi all!

I'm new in forum. I wrote this config for I2S. Instead of MCLK=256*Fs=12, 288000 MHz and CK=48KHz*32bit*2channel=3, 072000 MHz, I measured MCLK=4MHz and CK=1 MHz. My code is:

RCC_APB1PeriphClockCmd (RCC_APB1Periph_SPI2, ENABLE);

// ....................

/* Connect pins to I2S peripheral */

GPIO_PinAFConfig (PCM1804_PORTC, PCM1804_SCKI_PS, GPIO_AF_SPI2); // I2S2_SCKI GPIO_PinAFConfig (PCM1804_PORTB, PCM1804_I2S2_CK_PS, GPIO_AF_SPI2); // I2S2_CK GPIO_PinAFConfig (PCM1804_PORTB, PCM1804_I2S2_SD_PS, GPIO_AF_SPI2); // I2S2_SD GPIO_PinAFConfig (PCM1804_PORTB, PCM1804_I2S2_LRCK_PS, GPIO_AF_SPI2); // I2S2_LRCK , WS // I2S2 peripheral configuration I2S_InitTypeDef I2S2_InitStructure; SPI_I2S_DeInit (SPI2); /* For this standard, the WS signal is used to indicate which channel is being transmitted. It is activated one CK clock cycle before the first bit (MSB) is available. */ I2S2_InitStructure.I2S_Standard = I2S_Standard_Phillips; I2S2_InitStructure.I2S_DataFormat = I2S_DataFormat_24b; I2S2_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable; I2S2_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k; // I2S2_InitStructure.I2S_CPOL = I2S_CPOL_Low; // I2S2_InitStructure.I2S_Mode = I2S_Mode_MasterRx; // I2S_Init (SPI2, &I2S2_InitStructure); /* I2S_INTERRUPT */ NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init (&NVIC_InitStructure); /* Enable the Rx buffer not empty interrupt */ SPI_I2S_ITConfig (SPI2, SPI_I2S_IT_RXNE, ENABLE); // I2S clock configuration in system file is:

/************************* PLL Parameters *************************************/ 
 /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */ 
 #define PLL_M (uint32_t)8 
 #define PLL_N (uint32_t)336 
 
 /* SYSCLK = PLL_VCO / PLL_P */ 
 #define PLL_P (uint32_t)2 
 
 /* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */ 
 #define PLL_Q (uint32_t)7 
 
 /* PLLI2S_VCO = (HSE_VALUE Or HSI_VALUE / PLL_M) * PLLI2S_N 
 I2SCLK = PLLI2S_VCO / PLLI2S_R */ 
 #define PLLI2S_N (uint32_t)258 
 #define PLLI2S_R (uint32_t)3

//.................

/******************************************************************************/ 
 /* I2S clock configuration */ 
 /******************************************************************************/ 
 /* PLLI2S clock used as I2S clock source */ 
 RCC->CFGR &= ~RCC_CFGR_I2SSRC; 
 
 /* Configure PLLI2S */ 
 RCC->PLLI2SCFGR = (PLLI2S_N << 6) | (PLLI2S_R << 28); 
 
 /* Enable PLLI2S */ 
 RCC->CR |= ((uint32_t)RCC_CR_PLLI2SON); 
 
 /* Wait till PLLI2S is ready */ 
 while((RCC->CR & RCC_CR_PLLI2SRDY) == 0) 
 { 
 }

On disvovery board the oscillator frequency is 8MHz, and in stm32f4xx.h the HSE value is: #if !defined (HSE_VALUE) #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ Thank you ! Regards uprog #stm32f4-i2s
This topic has been closed for replies.

6 replies

uprogc
uprogcAuthor
Associate II
July 28, 2013
Posted on July 28, 2013 at 17:17

Hi !

I didnt found any solution yet. I use GCC configured with:

../gcc-linaro-4.6-210/configure 
--target=arm-none-eabi --prefix=/opt/ARM/arm-linaro-eabi-4.6/ --enable-multilib --enable-languages=c,c++ --with-newlib --with-gnu-as --with-gnu-ld --disable-nls --disable-shared --disable-threads --with-headers=newlib/libc/include --disable-libssp --disable-libstdcxx-pch --disable-libmudflap --disable-libgomp --disable-werror --with-system-zlib --disable-newlib-supplied-syscalls<br>Thread model: single<br>gcc version 4.6.2 20111004 (prerelease) (Linaro GCC 4.6-210)

And:

CFLAGS = -I. -IInclude -Iinclude -Iinc \<br> -c -fno-common -O2 -g -D
''assert_param(x)=''
-DARM_MATH_CM4 \<br> -mcpu=cortex-m4 -mthumb \<br> -mfloat-abi=hard -mfpu=fpv4-sp-d16 \<br> -fsingle-precision-constant #\

waclawek.jan
Super User
July 29, 2013
Posted on July 29, 2013 at 18:27

And what is the content of SPI_I2SPR after the setup?

JW

uprogc
uprogcAuthor
Associate II
July 29, 2013
Posted on July 29, 2013 at 22:37

Hi !

I don't know, because I have used a precompiled std. periph. static library and I can't watch the SPI_I2SPR register content.

Regards

uprog
Tesla DeLorean
Guru
July 29, 2013
Posted on July 29, 2013 at 22:40

Or print them via a console, or SWD?

If you can't get you debugger to dump arbitrary memory locations, you might want to find some different tools.

The PLL setting looked to be reasonable.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
waclawek.jan
Super User
July 30, 2013
Posted on July 30, 2013 at 11:59

> I don't know,

And how are we then supposed to know?

Although, in fact, we are not interested. *You* are. It was a hint that *you* should investigate the setting of this register.

> because I have used a precompiled std. periph. static library

Then don't. It might've been compiled with unexpected settings (e.g. with I2S_EXTERNAL_CLOCK_VAL set).

> and I can't watch the SPI_I2SPR register content.

You always can read it out after it has been set. You can also look at the disassembled binary.

JW

uprogc
uprogcAuthor
Associate II
October 16, 2013
Posted on October 16, 2013 at 13:44

With Keil it's working fine ! I have 256x48 kHz MCK clock signal.