初中生
最后登录1970-1-1
在线时间 小时
注册时间2016-3-16
|
- #include "bsp_transmission.h"
- #include "bsp_usart.h"
- #include <stdio.h>
- __IO uint16_t ReceiveBufffer[4] = {0};
- void DMA_MODE_Config(void)
- {
-
-
- /*DMA´«ÊäÊý¾ÝÁ÷1ͨdao 4 USART_RX*/
- DMA_InitTypeDef DMA_InitStructure;//µÚÒ»²½¶¨ÒåÒ»¸öDMAµÄ½á¹¹Ìå·½±ãÅäÖÃDMA
-
- RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_DMA1,ENABLE); //¿ªÆôDMA2ʱÖÓ
- DMA_DeInit(DMA1_Stream4);
- while(DMA_GetCmdStatus(DMA1_Stream4) != DISABLE) {}
- printf("ÐÄÈûÈû 1");
- DMA_InitStructure.DMA_Channel =DMA_Channel_4;//STM32Êý¾ÝÊÖ²á¿ÉÒÔÖªµÀDMA2µÄTXͨµÀ4Êý¾ÝÁ÷7
-
- DMA_InitStructure.DMA_PeripheralBaseAddr = USART_DR_BASE;//DMA´«ÊäµÄµØÖ·Èë¿Ú
-
- DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)ReceiveBufffer;//½«ËûËÍÈëÁËÒ»¸öÊý×é¡£ÊDz»ÊÇÒ²¿ÉÒÔ»»¸öµØ·½´©³öÀ´¡£ÊµÑé¡£
-
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//·½Ïò´ÓÄÚ´æµ½ÍâÉè
-
- DMA_InitStructure.DMA_BufferSize = 4;//Òª·¢Ë͵ÄÊý¾ÝÁ¿
-
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //ÍâÉèµØÖ·²»Ôö¼Ó¡£Ò»Ö±´ÓUSART1ÖнøÐÐÊä³ö
-
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //ÄÚ´æµØÖ·×ÔÔö¼Ó
- 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_Medium; //´«ÊäÓÅÏȼ¶±ð¡£
- DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
- DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; //½ûÓÃFIFO
-
- DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //´æ´¢Æ÷Í»·¢´«ÊäÒ»¸ö½ÚÅÄ
- DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //ÍâÉèÍ»·¢´«ÊäÒ»¸ö½ÚÅÄ
-
- DMA_Init(DMA1_Stream4, &DMA_InitStructure);
- DMA_Cmd(DMA1_Stream4, ENABLE);
- printf("ÐÄÈûÈû 2");
- while (DMA_GetCmdStatus(DMA1_Stream4) != ENABLE);//µÈ´ýÓÐЧ¡£
- printf("ÐÄÈûÈû 3");
- }
- void USART_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
-
-
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);//pb11 rx pb10 tx
-
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
-
- GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_USART3);
-
- GPIO_InitStructure.GPIO_Pin =GPIO_Pin_11;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Fast_Speed;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
-
- GPIO_Init(GPIOB,&GPIO_InitStructure);
-
- /**
- * ͨПñʽ
- * 1¸öÆðʼλ 8¸öÊý¾Ýλ 1¸öֹͣλ ÎÞУÑéλ
- **/
- USART_InitStructure.USART_BaudRate = 9600;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;//Ò»¸öÆðʼλ
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;;
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//²»Ê¹ÓÃÓ²¼þÁ÷¿ØÖÆ!!
-
- USART_Init(USART3,&USART_InitStructure);
- USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
- USART_Cmd(USART3,ENABLE);
-
- }
复制代码- #ifndef _TRANSMISSION_H
- #define _TRANSMISSION_H
- #include "stm32f4xx.h"
- #define rBuffer 4
- #define tBuffer 4
- #define USART_DR_BASE (USART3_BASE+0x04)
- void USART_GPIO_Config(void);
- void DMA_MODE_Config(void);
- #endif //_TRANSMISSION_H
复制代码 这个是DMA的配置以及.h文件- /**
- ******************************************************************************
- * @file main.c
- * @author WHY
- * @version V1.0
- * @date 2016-05-4
- * @brief ÓÃ1.5.1°æ±¾¿â½¨µÄ¹¤³ÌÄ£°å
- ******************************************************************************
- * @attention
- *
- *
- ******************************************************************************
- */
-
- #include "stm32f4xx.h"
- #include "bsp_usart.h"
- #include "bsp_transmission.h"
- #include <stdio.h>
- void Delay(__IO uint32_t nCount);
- extern __IO uint16_t ReceiveBufffer[4];
- uint16_t rxsaveBufffer;
- /**
- * @brief Ö÷º¯Êý
- * @param ÎÞ
- * @retval ÎÞ
- */
- int main(void)
- {
- // int i = 0;
- Debug_USART_Config();//这个主要是测试的 就是printf这个函数PA9TX PA10RX_PWM2 PWM3 PA9TX_PWM2
- NVIC_Configuration();
- printf("³õʼ»¯¿ªÊ¼\n");
- USART_GPIO_Config();
- DMA_MODE_Config();
- printf("DMAͨÐųõʼ\n");
- USART_DMACmd(USART3,USART_DMAReq_Rx, ENABLE);
-
-
- while(1)
- {
-
- }
- }
- void Delay(__IO uint32_t nCount)
- {
- for(; nCount != 0; nCount--);
- }
- /*********************************************END OF FILE**********************/
复制代码
一直找不到错误在哪里。求大神帮忙呀
|
|