完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "STM32f10x_lib.h"
//#include "platform_config.h" #define USART1_DR_Base 0x40013804 #define Sendbuff_size 35 vu8 TxBuffer[]= "111111111111111111111"; vu8 RxBuffer[]; /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ void RCC_Configuration(void); void GPIO_Configuration(void); void NVIC_Configuration(void); void DMA_Configuration(void); void USART1_Configuration(void); /* Private functions ---------------------------------------------------------*/ /******************************************************************************* * Function Name: main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { u8 index=0; #ifdef DEBUG debug(); #endif RCC_Configuration(); //配置系统时钟,设置系统时钟为72M GPIO_Configuration(); NVIC_Configuration(); //配置中断 USART1_Configuration(); DMA_Configuration(); //这里是开始DMA传输前的一些准备工作,将USART1模块设置成DMA方式工作 USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE); //开始一次DMA传输! DMA_Cmd(DMA1_Channel4,ENABLE); while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE) == RESET) {} RxBuffer[index++] = USART_ReceiveData(USART1); while(DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET) {} USART_SendData(USART1,RxBuffer[index]); while(1) {} } /******************************************************************************* * Function Name: RCC_Configuration * Description : Configures the different system clocks. * Input : None * Output : None * Return : None *******************************************************************************/ void RCC_Configuration(void) { ErrorStatus HSEStartUpStatus; /* Enable HSE */ RCC_DeInit(); RCC_HSEConfig(RCC_HSE_ON); /* Wait till HSE is ready */ HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); FLASH_SetLatency(FLASH_Latency_2); FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); /* Enable PLL */ RCC_PLLCmd(ENABLE); /* Wait till PLL is ready */ while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {} /* Select PLL as system clock source */ RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); /* Wait till PLL is used as system clock source */ while(RCC_GetSYSCLKSource() != 0x08) {} } RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC |RCC_APB2Periph_GPIOE| RCC_APB2Periph_AFIO|RCC_APB2Periph_USART1 , ENABLE); //打开外设D的时钟 // RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);/* Enable ADC1clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //开DMA时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOE, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //设定LED8灯控制脚PD7 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //I/O口的方向 GPIO_Init(GPIOD, &GPIO_InitStructure); } /******************************************************************************* * Function Name: NVIC_Configuration * Description : Configures Vector Table base location. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif } #ifdef DEBUG /******************************************************************************* * Function Name: assert_failed * Description : Reports the name of the source file and the source line number * where the assert_param error has occurred. * Input : - file: pointer to the source file name * - line: assert_param error line source number * Output : None * Return : None *******************************************************************************/ void assert_failed(u8* file, u32 line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %drn", file, line) */ /* Infinite loop */ while (1) { } } #endif void USART1_Configuration(void) { USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 9600;//设置 USART1的波特率 USART_InitStructure.USART_WordLength = USART_WordLength_8b;//设置数据位数 USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//发送 接受使能 USART_Init(USART1, &USART_InitStructure); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_Cmd(USART1, ENABLE); } void DMA_Configuration(void) { DMA_InitTypeDef DMA_InitStructure; DMA_DeInit(DMA1_Channel4); DMA_InitStructure.DMA_PeripheralBaseAddr =USART1_DR_Base;//外设基地址(数组的首地址,即内存中的地址) DMA_InitStructure.DMA_MemoryBaseAddr =(u32)TxBuffer;//DMA内存基地址 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;//外设作为数据传输的来源 DMA_InitStructure.DMA_BufferSize =Sendbuff_size;//定义指定DMA通道的DMA缓存的大小 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设地址寄存器递增 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//内存地址寄存器递增 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//外设数据宽度为32位 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;//内存数据宽度为32位 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;//工作在正常缓存模式 DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;//DMA通道6拥有高优先级 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//DMA通道6设置为内存到内存传输 DMA_Init(DMA1_Channel4, &DMA_InitStructure); } 串口助手不能收到数据,请教各位看看是什么问题? |
|
相关推荐
1个回答
|
|
请参考我们的代码.
|
|
|
|
只有小组成员才能发言,加入小组>>
745 浏览 0 评论
6357 浏览 1 评论
3953 浏览 7 评论
TIM3定时器输出PWM波控制LED灯的亮暗程度,PWM输出的高电平还有不同的值吗?
2460 浏览 11 评论
1804 浏览 5 评论
1194浏览 9评论
280浏览 1评论
553浏览 1评论
113浏览 0评论
1730浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 粤ICP备14022951号 )
GMT+8, 2024-1-10 10:27 , Processed in 0.388990 second(s), Total 42, Slave 37 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 深圳华秋电子有限公司
电子发烧友 (电路图) 粤公网安备 44030402000349 号 电信与信息服务业务经营许可证:粤 B2-20160233 工商网监 湘ICP备2023018690号