本帖最后由 dh0219 于 2016-6-22 08:41 编辑
我打开IIS2主发送 IIS3从发送 DMA双缓冲模式 清空发送buf之后 就开启DMA传输 一路IIS就会出现杂乱的数据
I2S2_Init(I2S_Standard_MSB,I2S_Mode_MasterTx,I2S_CPOL_High,I2S_DataFormat_16b);
I2S2_SampleRate_Set(DSDctrl.samplerate*2);
I2S2_TX_DMA_Init(audiodev.tbuf,audiodev.tbuf1,DSD_I2S_TX_DMA_BUFSIZE);
I2S3_TX_DMA_Init(audiodev.i2sbuf1,audiodev.i2sbuf2,DSD_I2S_TX_DMA_BUFSIZE); //ÅäÖÃTX DMA
i2s_tx_callback=DSD_i2s_dma_tx_callback;
audio_start();
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
原子哥 我开了两路IIS 一主一从 并在一起使用 都是发送模式 我开一路DMA正常 但是当我打开两路DMA的时候 就会有其中一路不正常 当我把两路的DMA发送数量改为bufsize的一半的时候 波形正常了 这种情况该怎么理解
原子哥,我在用dma传输串口数据,现在要实现的功能是将接收到的数据通过spi发送出去,现在遇到的问题是dma调试不通,我在串口中断中实现接收,但是进入不了中断,请帮忙看看,谢谢
下面是初始化部分
#if SYSTEM_SUPPORT_UCOS
#include "includes.h"
#endif
_DMA_UART1 DMA_UART1;
#if 1
#pragma import(__use_no_semihosting)
//±ê×¼¿aDèòaμÄÖ§3Öoˉêy
struct __FILE
{
int handle;
};
FILE __stdout;
_sys_exit(int x)
{
x = x;
}
int fputc(int ch, FILE *f)
{
while((USART1->SR&0X40)==0);//Ñ-»··¢Ëí,Ö±μ½·¢Ëííê±Ï
USART1->DR = (u8) ch;
return ch;
}
#endif
#define UART_Rx_DMA_Channel DMA1_Stream5
u8 USART_RX_BUF[11]; //½óêÕ»o3å,×î′óUSART_REC_LEN¸ö×Ö½ú.
void USATR1_Init(void) //′®¿ú1
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// Enable GPIO clock //
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
// Enable USART clock //
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
// Connect USART pins to AF7 //
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);
/* Configure USART Tx and Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; // ′®¿ú½óêÕIO¿úμÄéèÖÃ
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_Init(GPIOB, &GPIO_InitStructure);
DMA_Uart_Init();
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎTó2¼têy¾Yá÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//êÕ·¢Ä£ê½
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//ÇàÕ¼óÅÏ輶1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//×óóÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_Cmd(USART1, ENABLE);
USART_DMACmd(USART1,USART_DMAReq_Rx,ENABLE); //ê1Äü′®¿ú1μÄDMA½óêÕ
}
void DMA_Uart_Init(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);//DMA1ê±Öóê1Äü
DMA_DeInit(DMA1_Stream5); // // »Ö¸′è±ê¡Öμ
while (DMA_GetCmdStatus(DMA1_Stream5) != DISABLE){}//μè′yDMA¿éÅäÖÃ
/* ÅäÖÃ DMA Stream */
DMA_Cmd(DMA1_Stream5, DISABLE);
DMA_InitStructure.DMA_Channel = DMA_Channel_4; //í¨μàÑ¡Ôñ
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&USART1->DR;//DMAíaéèμØÖ·
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)DMA_UART1.Rx_Buf;//DMA ′æ′¢Æ÷0μØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//′æ′¢Æ÷μ½íaéèÄ£ê½
DMA_InitStructure.DMA_BufferSize = RX_BSIZE;//êy¾Y′«êäá¿
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//íaéè·ÇÔöá¿Ä£ê½
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//′æ′¢Æ÷Ôöá¿Ä£ê½
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//íaéèêy¾Y3¤¶è:8λ
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;//′æ′¢Æ÷êy¾Y3¤¶è:8λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;// ê1óÃÆÕí¨Ä£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;//ÖDμèóÅÏ輶
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//′æ′¢Æ÷í»·¢μ¥′Î′«êä
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//íaéèí»·¢μ¥′Î′«êä
DMA_Init(DMA1_Stream5, &DMA_InitStructure);//3õê¼»ˉDMA Stream
DMA_ClearFlag(DMA1_Stream5,DMA_FLAG_TCIF5);//Çå3yDMA1_Steam5′«êäíê3é±êÖ¾
DMA_Cmd(DMA1_Stream5, ENABLE);
}
void Uart_DMA_Rx_Data(void)//DMA_Stream_TypeDef *DMA_Streamx,u16 ndtr
{
DMA_Cmd(DMA1_Stream5, DISABLE); //1رÕDMA′«êä £¬·àÖ1¸éèÅ
//while (DMA_GetCmdStatus(DMA1_Stream5) != DISABLE){} //è·±£DMA¿éòÔ±»éèÖÃ
DMA_ClearFlag(DMA1_Stream5,DMA_FLAG_TCIF5); //Çå3yDMA1_Steam5′«êäíê3é±êÖ¾
DMA_UART1.Rx_len = RX_BSIZE - DMA_GetCurrDataCounter(UART_Rx_DMA_Channel); //»ñμýóêÕμ½μÄ×Ö½úêy
UART_Rx_DMA_Channel->NDTR = RX_BSIZE; // ÖØD¸3Öμ¼ÆêyÖ죬±ØDë′óóúμèóú×î′ó¿éÄü½óêÕμ½μÄêy¾YÖ¡êyÄ¿
// DMA_SetCurrDataCounter(DMA_Streamx,ndtr); //êy¾Y′«êäá¿
DMA_Cmd(DMA1_Stream5, ENABLE); //¿aÆôDMA′«êä
}
#if EN_USART1_RX //èç1ûê1Äüá˽óêÕ
void USART1_IRQHandler(void) //′®¿ú1ÖD¶Ï·tÎñ3ìDò
{
u8 i;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //½óêÕÖD¶Ï USART_IT_RXNE USART_IT_IDLE
{
Uart_DMA_Rx_Data();
USART_ReceiveData(USART1);
DMA_UART1.Rx_flag = 1;
/* for(i=0;i<11;i++)
{
USART_RX_BUF =USART_ReceiveData(USART1);//(USART1->DR); //¶á衽óêÕμ½μÄêy¾Y
}*/
}
}
#endif
[/mw_shl_code]
下面是主函数
DMA_UART1.busy_flag = 1;
DMA_UART1.Rx_flag = 0;
DMA_UART1.Rx_len = 0;
while(1)
{if(DMA_UART1.Rx_flag == 1)
{
// printf("½óêÕμ½êy¾Y ");
DMA_UART1.Rx_flag = 0;
for(j=0;j<DMA_UART1.Rx_len;j++)
{
printf("½óêÕêy¾Y£o%c ",DMA_UART1.Rx_Buf[j]);
}
else{
t3++; //ìáê¾Ïμí3ÕyÔúÔËDD
delay_ms(500);
if(t3==20)
{
BEEP=!BEEP;
t3=0;
}
程序直接进入else了,我现在用的不是mini板,是2系列的,原子哥帮忙看看,搞了好长时间了,谢谢
一周热门 更多>