STM32F407 定时器触发DMA 求助大神
【MCU实战经验】基于STM32F407的音频播放器设计
盘古UE-STM32F407工控板原理图
【STM32F429心得\疑问】+STM32F4之FSMC和FMC
STM32F429读取IO口传输的数据速率
STM32F407ZGT6 手摸芯片背部重启
STM32F4 SPI 动作时,软件片选信号被拉高,IO口程序逻辑失控
STM32F401RE NUCLEO求助,串口一直不能进中断
读取STM32F407内部温度传感器值错误
STM32F429多路内部ADC独立采集的办法
#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);
}
}
}
点评
评分
查看全部评分
yes!你和我的想法一致.进入hardfault是个不错的结果,如果真实越界了,你可以给个固定数据试一试.
我怎么感觉应该是用SCk引脚和MISO引脚,数字麦克风作为输出,单片机作为输入,你的单片机引脚用的是MOSI,是给数字麦克风输入数据.....
第二个问题,在中断里对数据进行转换,这个方法恐怕不好,建议是中断设定标志,中断外进行数据转换~
近期可能我也打算用这个测试,到时候一起研究
评分
查看全部评分
看来我想多了