你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

stm32f427的I2S问题

[复制链接]
colengol 提问时间:2015-2-1 10:39 /
本帖最后由 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*/



/**
* @brief  Configures the I2S Peripheral.
* @param  None
* @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);
}
/**
* @brief  Configures the I2S Peripheral.
* @param  None
* @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 -------------------------------------------------------*/
    /* Initialize  I2Sx 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 */

}



收藏 评论4 发布时间:2015-2-1 10:39

举报

4个回答
colengol 回答时间:2015-2-1 10:46:30
没人来吗?。。自己顶下!!!
colengol 回答时间:2015-2-1 11:01:11
不要沉啊!顶起。。。。
colengol 回答时间:2015-2-1 11:28:23
大神,快来吧!!!
dsjsjf 回答时间:2015-2-1 20:06:31
顶起来  

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版