stm32f427的I2S问题
本帖最后由 colengol 于 2015-2-1 11:13 编辑最近项目中用到I2S,研究过官方手册和例程后,准备自己配置下,但是第一步主时钟输出就失败了!主时钟输出是用示波器监测的,以下是代码,请大家帮忙看下,在下感激不尽!谢谢>>>
/* Exported define ------------------------------------------------------------*/
/* Uncomment the line below if you will use the I2S peripheral as a Master */
#define I2S_MASTER
/* Uncomment the line below if you will use the I2S peripheral as a Slave */
/* #define I2S_SLAVE */
/* Uncomment the line below if you will use the I2S2 peripheral */
#define I2S2_Select
/* Uncomment the line below if you will use the I2S3 peripheral */
#define I2S3_Select
/* IDT I2S2 Communication boards Interface */
#ifdef I2S2_Select
#define I2S2 SPI2
//#define I2S2ext I2S2ext
#define I2S2_CLK RCC_APB1Periph_SPI2
//#define I2S2_CLK_INIT RCC_APB1PeriphClockCmd
#define I2S2_WS_PIN GPIO_Pin_12
#define I2S2_WS_GPIO_PORT GPIOB
#define I2S2_WS_GPIO_CLK RCC_AHB1Periph_GPIOB
#define I2S2_WS_SOURCE GPIO_PinSource12
#define I2S2_WS_AF GPIO_AF_SPI2
#define I2S2_CK_PIN GPIO_Pin_13
#define I2S2_CK_GPIO_PORT GPIOB
#define I2S2_CK_GPIO_CLK RCC_AHB1Periph_GPIOB
#define I2S2_CK_SOURCE GPIO_PinSource13
#define I2S2_CK_AF GPIO_AF_SPI2
#define I2S2_SD_PIN GPIO_Pin_15
#define I2S2_SD_GPIO_PORT GPIOB
#define I2S2_SD_GPIO_CLK RCC_AHB1Periph_GPIOB
#define I2S2_SD_SOURCE GPIO_PinSource15
#define I2S2_SD_AF GPIO_AF_SPI2
#define I2S2ext_SD_PIN GPIO_Pin_14
#define I2S2ext_SD_GPIO_PORT GPIOB
#define I2S2ext_SD_GPIO_CLK RCC_AHB1Periph_GPIOB
#define I2S2ext_SD_SOURCE GPIO_PinSource14
#define I2S2ext_SD_AF GPIO_AF_SPI2
#define I2S2_MCK_PIN GPIO_Pin_6
#define I2S2_MCK_GPIO_PORT GPIOC
#define I2S2_MCK_GPIO_CLK RCC_AHB1Periph_GPIOC
#define I2S2_MCK_SOURCE GPIO_PinSource6
#define I2S2_MCK_AF GPIO_AF_SPI2//GPIO_AF_MCO//GPIO_AF_SPI2
#endif /*I2S2_Select*/
/**
* @briefConfigures the I2S Peripheral.
* @paramNone
* @retval None
*/
static void IDT0_I2S_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clocks */
RCC_AHB1PeriphClockCmd(I2S2_WS_GPIO_CLK | I2S2_CK_GPIO_CLK | \
I2S2_SD_GPIO_CLK | I2S2ext_SD_GPIO_CLK | I2S2_MCK_GPIO_CLK, ENABLE);
/* I2S GPIO Configuration --------------------------------------------------*/
/* Connect I2S pins to Alternate functions */
GPIO_PinAFConfig(I2S2_WS_GPIO_PORT, I2S2_WS_SOURCE, I2S2_WS_AF);
GPIO_PinAFConfig(I2S2_CK_GPIO_PORT, I2S2_CK_SOURCE, I2S2_CK_AF);
GPIO_PinAFConfig(I2S2_SD_GPIO_PORT, I2S2_SD_SOURCE, I2S2_SD_AF);
GPIO_PinAFConfig(I2S2ext_SD_GPIO_PORT, I2S2ext_SD_SOURCE, I2S2ext_SD_AF);
GPIO_PinAFConfig(I2S2_MCK_GPIO_PORT, I2S2_MCK_SOURCE, I2S2_MCK_AF);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_UP;//GPIO_PuPd_DOWN;
/* I2S WS pin configuration */
GPIO_InitStructure.GPIO_Pin = I2S2_WS_PIN;
GPIO_Init(I2S2_WS_GPIO_PORT, &GPIO_InitStructure);
/* I2S CK pin configuration */
GPIO_InitStructure.GPIO_Pin =I2S2_CK_PIN;
GPIO_Init(I2S2_CK_GPIO_PORT, &GPIO_InitStructure);
/* I2S SD pin configuration */
GPIO_InitStructure.GPIO_Pin = I2S2_SD_PIN;
GPIO_Init(I2S2_SD_GPIO_PORT, &GPIO_InitStructure);
/* I2S Extended SD pin configuration */
GPIO_InitStructure.GPIO_Pin =I2S2ext_SD_PIN;
GPIO_Init(I2S2ext_SD_GPIO_PORT, &GPIO_InitStructure);
/* I2S MCK pin configuration */
GPIO_InitStructure.GPIO_Pin = I2S2_MCK_PIN;
GPIO_Init(I2S2_MCK_GPIO_PORT, &GPIO_InitStructure);
}
/**
* @briefConfigures the I2S Peripheral.
* @paramNone
* @retval None
*/
static void IDT0_I2S_Config(void)
{
I2S_InitTypeDef I2S_InitStructure;
IDT0_I2S_GPIO_Config();
/* Peripheral Clock Enable -------------------------------------------------*/
/* Enable the I2Sx/I2Sx_ext clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
/* I2S configuration -------------------------------------------------------*/
/* InitializeI2Sx and I2Sxext peripherals */
SPI_I2S_DeInit(I2S2);
/* Configure the Audio Frequency, Standard and the data format */
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
I2S_InitStructure.I2S_Standard = I2S_Standard_PCMShort;//I2S_Standard_Phillips;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
#ifdef I2S_MASTER
/* Master full Duplex configuration ----------------------------------------*/
/* Configure I2Sx in Master Transmitter Mode */
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
I2S_Init(I2S2, &I2S_InitStructure);
/* Configure the I2Sx_ext (the second instance) in Slave Receiver Mode */
I2S_FullDuplexConfig(I2S2ext, &I2S_InitStructure);
/* Enable the I2Sx peripheral */
I2S_Cmd(I2S2, ENABLE);
/* Enable the I2Sx_ext peripheral for Full Duplex mode */
I2S_Cmd(I2S2ext, ENABLE);
#endif /* I2S_MASTER */
#ifdef I2S_SLAVE
/* Slave full Duplex configuration ----------------------------------------*/
/* Configure I2Sx in Slave Receiver Mode */
I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx;
I2S_Init(I2S2, &I2S_InitStructure);
/* Configure the I2Sx_ext (the second instance) in Slave Transmitter Mode */
I2S_FullDuplexConfig(I2S2ext, &I2S_InitStructure);
#endif /* I2S_SLAVE */
}
没人来吗?。。自己顶下!!! 不要沉啊!顶起。。。。 大神,快来吧!!! 顶起来
页:
[1]