硬汉嵌入式论坛

 找回密码
 立即注册
查看: 7505|回复: 8
收起左侧

[有问必答] SPI2中断进不去是为什么?

[复制链接]

25

主题

135

回帖

210

积分

高级会员

积分
210
发表于 2015-8-11 10:38:36 | 显示全部楼层 |阅读模式
有时钟和中断配置
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 ,ENABLE);
    /* SPI2 IRQ Channel configuration */
    NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
然后就是端口配置,这样应该就可以了吧,为什么进不了中断SPI2_IRQHandler();
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107294
QQ
发表于 2015-8-11 10:48:16 | 显示全部楼层
楼主贴一个完整的配置看下,估计是哪里没有配置到。
回复

使用道具 举报

25

主题

135

回帖

210

积分

高级会员

积分
210
 楼主| 发表于 2015-8-11 10:57:52 | 显示全部楼层
GPIO_InitTypeDef GPIO_InitStructure;
    I2S_InitTypeDef I2S_InitStructure;            
   
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_13 , GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_12, GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_15, GPIO_AF_SPI2);

    /* Configure SPI2 pins: CK, WS and SD */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13| GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(GPIO_AK5351_SCLK, &GPIO_InitStructure);
    //MCLK
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    //开启PD FSYNC
      GPIO_InitStructure.GPIO_Pin =Pin_AK5351_PD;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_Init(GPIO_AK5351_PD, &GPIO_InitStructure);
//        
        
        GPIO_InitStructure.GPIO_Pin =Pin_AK5351_FSYNC;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_Init(GPIO_AK5351_FSYNC, &GPIO_InitStructure);
   
    //设定I2S
    //飞利浦标准
    I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
    //32bit数据格式
    I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_32b;
    //MCLK输出
      I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
    //采样率4.8K
    I2S_InitStructure.I2S_AudioFreq = (u32)4800;
    //无数据同步时钟拉低
      I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
    //初始化I2S_2
      I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
      I2S_Init(SPI2, &I2S_InitStructure);
    //启动I2S_2
    I2S_Cmd(SPI2, ENABLE);
   
    //Reset ADC FSYNC=H
    GPIO_ResetBits(GPIO_AK5351_PD, Pin_AK5351_PD);
    GPIO_ResetBits(GPIO_AK5351_FSYNC,Pin_AK5351_FSYNC);
    bsp_DelayMS(5);
    GPIO_SetBits(GPIO_AK5351_PD, Pin_AK5351_PD);   

    //配置I2S_2读取中断
    SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);

       //等待读取中断结束(ADC准备过程)
    while (RxLeftIdx<DataLength*2 ||RxRightIdx<DataLength*2);
    RxLeftIdx=0;
    RxRightIdx=0;
    SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, DISABLE);
回复

使用道具 举报

25

主题

135

回帖

210

积分

高级会员

积分
210
 楼主| 发表于 2015-8-11 11:00:47 | 显示全部楼层

回 eric2013 的帖子

eric2013:楼主贴一个完整的配置看下,估计是哪里没有配置到。 (2015-08-11 10:48) 
这个程序之前在STM32F103上用的,现在改407了程序在之前的基础上做了一下修改
回复

使用道具 举报

25

主题

135

回帖

210

积分

高级会员

积分
210
 楼主| 发表于 2015-8-11 17:14:05 | 显示全部楼层

回 eric2013 的帖子

eric2013:楼主贴一个完整的配置看下,估计是哪里没有配置到。 (2015-08-11 10:48) 
有什么问题吗,麻烦看一下
GPIO_InitTypeDef GPIO_InitStructure;
    I2S_InitTypeDef I2S_InitStructure;            
   
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_13 , GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_12, GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIOB, GPIO_Pin_15, GPIO_AF_SPI2);

    /* Configure SPI2 pins: CK, WS and SD */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13| GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(GPIO_AK5351_SCLK, &GPIO_InitStructure);
    //MCLK
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    //开启PD FSYNC
      GPIO_InitStructure.GPIO_Pin =Pin_AK5351_PD;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_Init(GPIO_AK5351_PD, &GPIO_InitStructure);
//        
        
        GPIO_InitStructure.GPIO_Pin =Pin_AK5351_FSYNC;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_Init(GPIO_AK5351_FSYNC, &GPIO_InitStructure);
   
    //设定I2S
    //飞利浦标准
    I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
    //32bit数据格式
    I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_32b;
    //MCLK输出
      I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
    //采样率4.8K
    I2S_InitStructure.I2S_AudioFreq = (u32)4800;
    //无数据同步时钟拉低
      I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
    //初始化I2S_2
      I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
      I2S_Init(SPI2, &I2S_InitStructure);
    //启动I2S_2
    I2S_Cmd(SPI2, ENABLE);
   
    //Reset ADC FSYNC=H
    GPIO_ResetBits(GPIO_AK5351_PD, Pin_AK5351_PD);
    GPIO_ResetBits(GPIO_AK5351_FSYNC,Pin_AK5351_FSYNC);
    bsp_DelayMS(5);
    GPIO_SetBits(GPIO_AK5351_PD, Pin_AK5351_PD);   

    //配置I2S_2读取中断
    SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);

       //等待读取中断结束(ADC准备过程)
    while (RxLeftIdx<DataLength*2 ||RxRightIdx<DataLength*2);
    RxLeftIdx=0;
    RxRightIdx=0;
    SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, DISABLE);
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107294
QQ
发表于 2015-8-12 08:57:12 | 显示全部楼层
1. 时钟配置

    /* 打开 I2S2 APB1 时钟 */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

          RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
         RCC_PLLI2SCmd(ENABLE);
回复

使用道具 举报

25

主题

135

回帖

210

积分

高级会员

积分
210
 楼主| 发表于 2015-8-12 15:05:17 | 显示全部楼层

回 eric2013 的帖子

eric2013:1. 时钟配置

    /* 打开 I2S2 APB1 时钟 */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

....... (2015-08-12 08:57) 
是这样的,可以了,谢谢,以前在103上没有这个设置,请问有没有SPI/I2S相关的407的资料
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107294
QQ
发表于 2015-8-12 21:57:25 | 显示全部楼层

回 明天tcx 的帖子

明天tcx:是这样的,可以了,谢谢,以前在103上没有这个设置,请问有没有SPI/I2S相关的407的资料 (2015-08-12 15:05) 
这个没有哦,主要的函数看官方的参考手册。
回复

使用道具 举报

25

主题

135

回帖

210

积分

高级会员

积分
210
 楼主| 发表于 2015-8-13 17:22:07 | 显示全部楼层

回 eric2013 的帖子

eric2013:这个没有哦,主要的函数看官方的参考手册。 (2015-08-12 21:57) 
麻烦再看一下这样配置为什么I2S_MCK和SCK脚没输出固定频率波形
GPIO_InitTypeDef GPIO_InitStructure;
    I2S_InitTypeDef I2S_InitStructure;            
    RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
  RCC_PLLI2SCmd(ENABLE);
    GPIO_PinAFConfig(GPIO_AK5351_SCLK, Pin_AK5351_SCLK , GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIO_AK5351_SCLK, Pin_AK5351_LRCK , GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIO_AK5351_SCLK, Pin_AK5351_SDATA, GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIO_AK5351_MCLK, Pin_AK5351_MCLK, GPIO_AF_SPI2);
    /* Configure SPI2 pins: CK, WS and SD */
    GPIO_InitStructure.GPIO_Pin = Pin_AK5351_SCLK | Pin_AK5351_LRCK | Pin_AK5351_SDATA;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIO_AK5351_SCLK, &GPIO_InitStructure);
    //MCLK
    GPIO_InitStructure.GPIO_Pin = Pin_AK5351_MCLK;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(GPIO_AK5351_MCLK, &GPIO_InitStructure);

//开启PD FSYNC
//GPIO_PinAFConfig(GPIO_AK5351_PD,Pin_AK5351_PD, GPIO_AF_I2S3ext);
    GPIO_InitStructure.GPIO_Pin =Pin_AK5351_PD;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIO_AK5351_PD, &GPIO_InitStructure);
    //        
    GPIO_InitStructure.GPIO_Pin =Pin_AK5351_FSYNC;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIO_AK5351_FSYNC, &GPIO_InitStructure);
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
    RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
    //设定I2S
    //飞利浦标准
    I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
    //32bit数据格式
    I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_32b;
    //MCLK输出
  I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
    //采样率4.8K
    I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_32k ;//(u32)4800
    //无数据同步时钟拉低
  I2S_InitStructure.I2S_CPOL = I2S_CPOL_High;
    //初始化I2S_2
  I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
  I2S_Init(SPI2, &I2S_InitStructure);
    //启动I2S_2
    I2S_Cmd(SPI2, ENABLE);
   
    //Reset ADC FSYNC=H
    GPIO_ResetBits(GPIO_AK5351_PD, Pin_AK5351_PD);
    GPIO_ResetBits(GPIO_AK5351_FSYNC,Pin_AK5351_FSYNC);
    bsp_DelayMS(5);
    GPIO_SetBits(GPIO_AK5351_PD, Pin_AK5351_PD);   

    //配置I2S_2读取中断
    SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);

     //等待读取中断结束(ADC准备过程)
    while (RxLeftIdx<DataLength*2 ||RxRightIdx<DataLength*2);
    RxLeftIdx=0;
    RxRightIdx=0;
   
    SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, DISABLE);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-25 02:55 , Processed in 0.183951 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表