小学生
最后登录1970-1-1
在线时间 小时
注册时间2023-1-18
|
本帖最后由 糖分get 于 2023-2-16 22:42 编辑
我想知道是否是因为型号不支持还是因为dma的问题,亦或是配置的问题,我单独使用i2s模块时可以正常输出音频,但使用dma就不行了
void i2s_GPIO_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_15 | GPIO_Pin_13 | GPIO_Pin_12 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void i2s_init()
{
I2S_InitTypeDef i2s_InitStructure;
i2s_GPIO_Init();
RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE);
i2s_InitStructure.I2S_Mode=I2S_Mode_MasterTx;
i2s_InitStructure.I2S_Standard=I2S_Standard_Phillips;
i2s_InitStructure.I2S_DataFormat=I2S_DataFormat_16b;
i2s_InitStructure.I2S_MCLKOutput=I2S_MCLKOutput_Enable;
i2s_InitStructure.I2S_AudioFreq=I2S_AudioFreq_44k;
i2s_InitStructure.I2S_CPOL=I2S_CPOL_Low;
I2S_Init(SPI2,&i2s_InitStructure);
I2S_Cmd(SPI2,ENABLE);
}
void I2S_DMA_Config(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
DMA_InitTypeDef DMA_InitStructure;
//dma中断配置,查手册,i2s2发送使用dma1通道5
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStruct.NVIC_IRQChannel = DMA1_Channel5_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStruct);
// 开启DMA时钟
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
// 设置DMA源地址:数据寄存器地址*/
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&SPI2->DR;
// 内存地址(要传输的变量的指针)
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SendBuff2;
// 方向:从内存到外设
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
// 传输大小
DMA_InitStructure.DMA_BufferSize =sizeof(SendBuff2);
// 外设地址不增
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
// 内存地址自增
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
// 外设数据单位 16bit
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
// 内存数据单位 16bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_HalfWord;
// DMA模式,一次模式
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal ;
//DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
// 优先级:中
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
// 禁止内存到内存的传输
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
// 配置DMA通道
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
//使能DMA全满中断
DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE);
// 使能DMA
DMA_Cmd (DMA1_Channel5,ENABLE);
}
#include "bsp_led.h"
void DMA1_Channel5_IRQHandler(void)
{
if(DMA_GetITStatus(DMA1_FLAG_TC5)!= RESET)//传输全部完成中断
{
DMA_ClearITPendingBit(DMA1_IT_TC5);
LED1(0);
LED2(0);
LED3(0);
DMA_Cmd(DMA1_Channel5,DISABLE);
SPI_I2S_DMACmd(SPI2,SPI_I2S_DMAReq_Tx,DISABLE);
}
}
|
|