完善资料让更多小伙伴认识你,还能领取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个回答
|
|
请参考我们的代码.
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1632 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1559 浏览 1 评论
985 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
688 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1605 浏览 2 评论
1869浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
652浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
520浏览 3评论
539浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
508浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 06:05 , Processed in 0.816984 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号