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

查看: 7502|回复: 1

STM32F407 I2S DMA 数据收不到 程序如下,牛人请看一下

[复制链接]

1

主题

1

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2013-8-12 01:23:09 | 显示全部楼层 |阅读模式
__IO uint32_t  I2S_RX_buffer[1024]={0x00};
__IO uint32_t RX_XferCplt=0;
/* Mask for the bit EN of the I2S CFGR register */
#define I2S_ENABLE_MASK                 0x0400
/* Delay for the Codec to be correctly reset */
#define CODEC_RESET_DELAY               0x4FFF
/* Codec audio Standards */
#ifdef I2S_STANDARD_PHILLIPS
 #define  CODEC_STANDARD                0x04
 #define I2S_STANDARD                   I2S_Standard_Phillips        
#elif defined(I2S_STANDARD_MSB)
 #define  CODEC_STANDARD                0x00
 #define I2S_STANDARD                   I2S_Standard_MSB   
#elif defined(I2S_STANDARD_LSB)
 #define  CODEC_STANDARD                0x08
 #define I2S_STANDARD                   I2S_Standard_LSB   
#else
 #error "Error: No audio communication standard selected !"
#endif /* I2S_STANDARD */
#define CODEC_I2S                      SPI3
#define I2Sxext                        I2S3ext
#define CODEC_I2S_CLK                  RCC_APB1Periph_SPI3
#define CODEC_I2S_ADDRESS              0x40003C0C
#define CODEC_I2S_GPIO_AF              GPIO_AF_SPI3
#define CODEC_I2S_IRQ                  SPI3_IRQn
#define CODEC_I2S_GPIO_CLOCK           (RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOA)
#define CODEC_I2S_WS_PIN               GPIO_Pin_4
#define CODEC_I2S_SCK_PIN              GPIO_Pin_10
#define CODEC_I2S_SD_PIN               GPIO_Pin_12
#define CODEC_I2S_SI_PIN               GPIO_Pin_11
#define CODEC_I2S_MCK_PIN              GPIO_Pin_7
#define CODEC_I2S_WS_PINSRC            GPIO_PinSource4
#define CODEC_I2S_SCK_PINSRC           GPIO_PinSource10
#define CODEC_I2S_SD_PINSRC            GPIO_PinSource12
#define CODEC_I2S_SI_PINSRC            GPIO_PinSource11
#define CODEC_I2S_MCK_PINSRC           GPIO_PinSource7
#define CODEC_I2S_GPIO                 GPIOC
#define CODEC_I2S_WS_GPIO              GPIOA
#define CODEC_I2S_MCK_GPIO             GPIOC
#define Audio_I2S_IRQHandler           SPI3_IRQHandler
 /* I2S DMA Stream definitions */
 #define AUDIO_I2S_DMA_CLOCK            RCC_AHB1Periph_DMA1
 #define AUDIO_I2S_DMA_STREAM           DMA1_Stream5
 #define AUDIO_I2S_DMA_DREG             CODEC_I2S_ADDRESS
 #define AUDIO_I2S_DMA_CHANNEL          DMA_Channel_0
 #define AUDIO_I2S_DMA_IRQ              DMA1_Stream5_IRQn
 #define AUDIO_I2S_DMA_FLAG_TC          DMA_FLAG_TCIF5
 #define AUDIO_I2S_DMA_FLAG_HT          DMA_FLAG_HTIF5
 #define AUDIO_I2S_DMA_FLAG_FE          DMA_FLAG_FEIF5
 #define AUDIO_I2S_DMA_FLAG_TE          DMA_FLAG_TEIF5
 #define AUDIO_I2S_DMA_FLAG_DME         DMA_FLAG_DMEIF5
 #define Audio_MAL_I2S_IRQHandler       DMA1_Stream5_IRQHandler
 /* I2S DMA RX Stream definitions */
 #define AUDIO_I2S_DMA_RX_CLOCK            RCC_AHB1Periph_DMA1
 #define AUDIO_I2S_DMA_RX_STREAM           DMA1_Stream0
 #define AUDIO_I2S_DMA_RX_DREG             CODEC_I2S_ADDRESS
 #define AUDIO_I2S_DMA_RX_CHANNEL          DMA_Channel_3
 #define AUDIO_I2S_DMA_RX_IRQ              DMA1_Stream0_IRQn
 #define AUDIO_I2S_DMA_RX_FLAG_TC          DMA_FLAG_TCIF0
static void Codec_GPIO_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
 
  /* Enable Reset GPIO Clock */
  RCC_AHB1PeriphClockCmd(AUDIO_RESET_GPIO_CLK,ENABLE);
 
  /* Audio reset pin configuration -------------------------------------------------*/
  GPIO_InitStructure.GPIO_Pin = AUDIO_RESET_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_Init(AUDIO_RESET_GPIO, &GPIO_InitStructure);   
 
  /* Enable I2S and I2C GPIO clocks */
  RCC_AHB1PeriphClockCmd(CODEC_I2C_GPIO_CLOCK | CODEC_I2S_GPIO_CLOCK, ENABLE);
  /* CODEC_I2C SCL and SDA pins configuration -------------------------------------*/
  GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SCL_PIN | CODEC_I2C_SDA_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_Init(CODEC_I2C_GPIO, &GPIO_InitStructure);    
  /* Connect pins to I2C peripheral */
  GPIO_PinAFConfig(CODEC_I2C_GPIO, CODEC_I2S_SCL_PINSRC, CODEC_I2C_GPIO_AF); 
  GPIO_PinAFConfig(CODEC_I2C_GPIO, CODEC_I2S_SDA_PINSRC, CODEC_I2C_GPIO_AF); 
  /* CODEC_I2S pins configuration: WS, SCK and SD pins -----------------------------*/
  GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN | CODEC_I2S_SD_PIN|CODEC_I2S_SI_PIN;
  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_NOPULL;
  GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);
  GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF);
 GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SD_PINSRC, CODEC_I2S_GPIO_AF);
 GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SI_PINSRC, GPIO_AF_I2S3ext);
 
 GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN ;
 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_NOPULL;
 GPIO_Init(CODEC_I2S_WS_GPIO, &GPIO_InitStructure);
 GPIO_PinAFConfig(CODEC_I2S_WS_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF);
  

  /* CODEC_I2S pins configuration: MCK pin */
  GPIO_InitStructure.GPIO_Pin = CODEC_I2S_MCK_PIN;
  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_NOPULL;
  GPIO_Init(CODEC_I2S_MCK_GPIO, &GPIO_InitStructure);  
  /* Connect pins to I2S peripheral  */
  GPIO_PinAFConfig(CODEC_I2S_MCK_GPIO, CODEC_I2S_MCK_PINSRC, CODEC_I2S_GPIO_AF);
}
static void Codec_AudioInterface_Init(uint32_t AudioFreq)
{
  I2S_InitTypeDef I2S_InitStructure;
//   DAC_InitTypeDef  DAC_InitStructure;
  /* Enable the CODEC_I2S peripheral clock */
  RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE);
 
  /* CODEC_I2S peripheral configuration */
  SPI_I2S_DeInit(CODEC_I2S);
  I2S_InitStructure.I2S_AudioFreq = AudioFreq;
  I2S_InitStructure.I2S_Standard = I2S_STANDARD;
  I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
  I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
   I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
  
  I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
  
  I2S_Init(CODEC_I2S, &I2S_InitStructure);
  I2S_FullDuplexConfig(I2S3ext, &I2S_InitStructure);
 
   I2S_Cmd(I2Sxext, ENABLE);
}
void Audio_MAL_I2S_RX_Init(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;  
 /* Enable the DMA clock */
    RCC_AHB1PeriphClockCmd(AUDIO_I2S_DMA_RX_CLOCK , ENABLE);
   
    /* Configure the DMA Stream */
    DMA_Cmd(AUDIO_I2S_DMA_RX_STREAM, DISABLE);
    DMA_DeInit(AUDIO_I2S_DMA_RX_STREAM);
   DMA_InitStructure.DMA_Channel =AUDIO_I2S_DMA_RX_CHANNEL; 
    DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40003C0C;
     DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)I2S_RX_buffer;      /* This field will be configured in play function */
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
    DMA_InitStructure.DMA_BufferSize = (uint32_t)0xFFFE;      /* This field will be configured in play function */
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
 
   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
   DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;       
    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; 
     DMA_Init(AUDIO_I2S_DMA_RX_STREAM, &DMA_InitStructure);
   
   DMA_ITConfig(AUDIO_I2S_DMA_RX_STREAM, DMA_IT_TC, ENABLE);
  
    NVIC_InitStructure.NVIC_IRQChannel = AUDIO_I2S_DMA_RX_IRQ ;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
  
   SPI_I2S_ITConfig(I2S3ext, SPI_I2S_IT_RXNE, ENABLE);
     I2S_Cmd(I2S3ext, ENABLE);  
   SPI_I2S_DMACmd(I2S3ext, SPI_I2S_DMAReq_Rx, ENABLE);
     
}
void DMA1_Stream0_IRQHandler(void)
{
 if (DMA_GetFlagStatus(AUDIO_I2S_DMA_RX_STREAM, AUDIO_I2S_DMA_RX_FLAG_TC) != RESET)
 { 
  DMA_Cmd(AUDIO_I2S_DMA_RX_STREAM, DISABLE);
   DMA_ClearFlag(AUDIO_I2S_DMA_RX_STREAM, AUDIO_I2S_DMA_RX_FLAG_TC);
   RX_XferCplt=1;
  }
}
 void recode_wav(void)  
{
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)I2S_RX_buffer;
    DMA_InitStructure.DMA_BufferSize =1024;
  DMA_Init(AUDIO_I2S_DMA_RX_STREAM, &DMA_InitStructure);
    /* Enable the I2S DMA Stream*/
  DMA_Cmd(AUDIO_I2S_DMA_RX_STREAM, ENABLE); 
}
 
当执行recode_wav() 时一直接收不到数据,DMA中断也能进入,不知怎么回事?
 
 
 
回复

使用道具 举报

0

主题

1

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2013-10-11 17:03:17 | 显示全部楼层

回复:STM32F407 I2S DMA 数据收不到 程序如下,牛人请看一下

楼主的问题解决了吗?
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版