我是靠谱客的博主 甜蜜世界,最近开发中收集的这篇文章主要介绍matlab pdm转pcm_STM32F407 PDM转PCM问题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

代码如下:

#include "sph0644.h"

#include "pdm_filter.h"

#define INTERNEL_BUFF_SIZE      64

#define PCM_OUT_SIZE            16

PDMFilter_InitStruct Filter;

u16 PDM_Output_Buffer[PCM_OUT_SIZE];

u16 *pAudioRecBuf;

u16 InternalBuffer[INTERNEL_BUFF_SIZE];

u16 InternalBufferSize = 0;

static void Sph0644_Config(void)

{

GPIO_InitTypeDef  GPIO_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

RCC_AHB1PeriphClockCmd(SPI_SCK_GPIO_CLK|SPI_MOSI_GPIO_CLK, ENABLE);//ʹÄÜÍâÉèGPIOB,GPIOCʱÖÓ

GPIO_InitStructure.GPIO_Pin = SPI_SCK_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//¸´Óù¦ÄÜ

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//ÍÆÍì

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//ÉÏÀ­

GPIO_Init(SPI_SCK_GPIO_PORT, &GPIO_InitStructure);//³õʼ»¯

GPIO_InitStructure.GPIO_Pin =SPI_MOSI_PIN;

GPIO_Init(SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);//³õʼ»¯

GPIO_PinAFConfig(SPI_SCK_GPIO_PORT,SPI_SCK_SOURCE,SPI_SCK_AF);        //PB13,AF5  I2S_SCLK

GPIO_PinAFConfig(SPI_MOSI_GPIO_PORT,SPI_MOSI_SOURCE,SPI_MOSI_AF);        //PC3 ,AF5  I2S_DACDATA

I2S2_Init(I2S_Standard_LSB,I2S_Mode_MasterRx,I2S_CPOL_High,I2S_DataFormat_16b);

I2S2_SampleRate_Set(32000);   //ÉèÖòÉÑùÂÊ

// Configure the SPI interrupt priority

NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 6;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

SPI_I2S_ITConfig(SPI2,SPI_I2S_IT_RXNE,ENABLE);

}

void Sph0644_Init(void)

{

//Enable CRC module/*

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);

//ÅäÖÃI2S2£¬CLKƵÂÊ1024MHz

Sph0644_Config();

//16KHz,ÔÚ´Ë֮ǰ£¬±ØÐ뿪ÆôCRCʱÖÓ£¬·ñÔò½øÈëËÀÑ­»·

Filter.LP_HZ = 8000;

Filter.HP_HZ = 10;

Filter.Fs = 16000;

Filter.Out_MicChannels = 1;

Filter.In_MicChannels = 1;

PDM_Filter_Init(&Filter);

}

void Sph0644_Start(void)

{

pAudioRecBuf = PDM_Output_Buffer;

I2S_Cmd(SPI2,ENABLE);

}

void Sph0644_Stop(void)

{

I2S_Cmd(SPI2,DISABLE);

}

void SPI2_IRQHandler(void)

{

u16 app;

u16 volume;

if(SPI_GetITStatus(SPI2,SPI_I2S_IT_RXNE) == SET)

{

app = SPI_I2S_ReceiveData(SPI2);

InternalBuffer[InternalBufferSize++] = HTONS(app);

if(InternalBufferSize >= INTERNEL_BUFF_SIZE)

{

InternalBufferSize = 0;

volume = 50;

PDM_Filter_64_LSB((u8*)InternalBuffer,pAudioRecBuf,volume,&Filter);

}

}

}

最后

以上就是甜蜜世界为你收集整理的matlab pdm转pcm_STM32F407 PDM转PCM问题的全部内容,希望文章能够帮你解决matlab pdm转pcm_STM32F407 PDM转PCM问题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部