stm32f207zg uart1配置
来源:互联网 发布:淘宝号封了会怎么样 编辑:程序博客网 时间:2024/06/13 05:09
**
******************************************************************************
* @file Project/STM32F2xx_StdPeriph_Template/main.c
* @author MCD Application Team
* @version V1.1.0
* @date 13-April-2012
* @brief Main program body
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
******************************************************************************
* @file Project/STM32F2xx_StdPeriph_Template/main.c
* @author MCD Application Team
* @version V1.1.0
* @date 13-April-2012
* @brief Main program body
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include<stdio.h>
#include "stm32f2xx.h"
#include "stm322xg_eval.h"
/** @addtogroup Template_Project
* @{
*/
#include "main.h"
#include<stdio.h>
#include "stm32f2xx.h"
#include "stm322xg_eval.h"
/** @addtogroup Template_Project
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define MESSAGE1 " STM32F2xx "
#define MESSAGE2 " Device running on "
#define MESSAGE3 " STM322xG-EVAL "
/* Private define ------------------------------------------------------------*/
#define MESSAGE1 " STM32F2xx "
#define MESSAGE2 " Device running on "
#define MESSAGE3 " STM322xG-EVAL "
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static __IO uint32_t TimingDelay;
/* Private variables ---------------------------------------------------------*/
static __IO uint32_t TimingDelay;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program.
* @param None
* @retval None
*/
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
USART_GetFlagStatus(USART1, USART_FLAG_TC);
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
* @brief Main program.
* @param None
* @retval None
*/
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
USART_GetFlagStatus(USART1, USART_FLAG_TC);
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
USART_SendData(USART1, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{}
return ch;
}
}
void RCC_Configuration(void)
{
RCC_DeInit(); //RCC寄存器初始化
RCC_HSEConfig(RCC_HSE_ON); //使用外部时钟
if(RCC_WaitForHSEStartUp() == SUCCESS) //等待外部时钟启动
{
RCC_PLLCmd(DISABLE); //配置PLL前应先关闭主PLL
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //选择PLL时钟为系统时钟 RCC_HCLKConfig(RCC_SYSCLK_Div1); //HCLK(AHB)时钟为系统时钟1分频
RCC_PCLK1Config(RCC_HCLK_Div4); //PCLK1(APB1)时钟为HCLK时钟8分频,则TIM2时钟为HCLK时钟4分频
RCC_PCLK2Config(RCC_HCLK_Div2); //PCLK2(APB2)时钟为HCLK时钟2分频
RCC_PLLConfig(RCC_PLLSource_HSE, 25, 336, 2, 7); //PLL时钟配置,公式详见‘system_stm43f4xx.c’ Line149
RCC_PLLCmd(ENABLE); //PLL时钟开启
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } //等待PLL时钟准备好
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA, ENABLE );
/* Connect PXx to USARTx_Tx*/
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
{
RCC_DeInit(); //RCC寄存器初始化
RCC_HSEConfig(RCC_HSE_ON); //使用外部时钟
if(RCC_WaitForHSEStartUp() == SUCCESS) //等待外部时钟启动
{
RCC_PLLCmd(DISABLE); //配置PLL前应先关闭主PLL
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //选择PLL时钟为系统时钟 RCC_HCLKConfig(RCC_SYSCLK_Div1); //HCLK(AHB)时钟为系统时钟1分频
RCC_PCLK1Config(RCC_HCLK_Div4); //PCLK1(APB1)时钟为HCLK时钟8分频,则TIM2时钟为HCLK时钟4分频
RCC_PCLK2Config(RCC_HCLK_Div2); //PCLK2(APB2)时钟为HCLK时钟2分频
RCC_PLLConfig(RCC_PLLSource_HSE, 25, 336, 2, 7); //PLL时钟配置,公式详见‘system_stm43f4xx.c’ Line149
RCC_PLLCmd(ENABLE); //PLL时钟开启
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) { } //等待PLL时钟准备好
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA, ENABLE );
/* Connect PXx to USARTx_Tx*/
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
/* Connect PXx to USARTx_Rx*/
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
// RCC_APB2PeriphClockCmd( USART1, ENABLE );
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // 选中管脚9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure); // 选择A端口
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
//IO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;/
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // 选中管脚9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure); // 选择A端口
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
//IO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;/
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void USART1_Configuration(void)
{
void USART1_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_DeInit(USART1);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
USART_DeInit(USART1);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
USART_InitStructure.USART_BaudRate = 115200; // 波特率为:115200
USART_InitStructure.USART_WordLength = USART_WordLength_8b; // 8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1; // 在帧结尾传输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; // 发送使能+接收使能
/* Configure USART1 basic and asynchronous paramters */
USART_Init(USART1, &USART_InitStructure);
//USART1->BRR=0x0139; //选择A端口
USART_Cmd(USART1, ENABLE); //USART1总开关:开启
}
USART_InitStructure.USART_WordLength = USART_WordLength_8b; // 8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1; // 在帧结尾传输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; // 发送使能+接收使能
/* Configure USART1 basic and asynchronous paramters */
USART_Init(USART1, &USART_InitStructure);
//USART1->BRR=0x0139; //选择A端口
USART_Cmd(USART1, ENABLE); //USART1总开关:开启
}
int main(void)
{
RCC_Configuration();
SystemCoreClockUpdate();
GPIO_Configuration();
USART1_Configuration();
while(1)
{
printf("风萧萧兮易水寒,壮士一去兮不复还\r\n");
printf("屈原:离骚\r\n");
}
}
{
RCC_Configuration();
SystemCoreClockUpdate();
GPIO_Configuration();
USART1_Configuration();
while(1)
{
printf("风萧萧兮易水寒,壮士一去兮不复还\r\n");
printf("屈原:离骚\r\n");
}
}
/**
* @brief Inserts a delay time.
* @param nTime: specifies the delay time length, in 10 ms.
* @retval None
*/
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
}
/**
* @brief Decrements the TimingDelay variable.
* @param None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
* @brief Decrements the TimingDelay variable.
* @param None
* @retval None
*/
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
while (1)
{
}
}
#endif
/**
* @}
*/
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
在此芯片上串口1和gpio不在同一个总线上,配置时注意,此程序在意法公司stm32f2xx库之上进行配置,函数简单明确;
0 0
- stm32f207zg uart1配置
- STM32F207ZG型号gpio配置
- UART1配置为打印口
- C8051F120单片机双串口配置(uart0,uart1)
- STM32F207ZG GPIO口学习
- mega128--uart1
- STM8 uart1
- uart1 读写程序
- DM6467之UART1
- STM32F103ZE和STM32F207ZG的芯片区别
- STM32 UART1 DMA 发送数据
- UART1口的程序编写
- STM32F407 Discovery uart1串口通信
- davinci 6446 UART1 rs485驱动
- DM6467 UART1 REGS
- STM8学习笔记---串口uart1
- 新路程------hi3516a uart1 rs485
- LPC17xx Uart0,Uart1,Uart2,Uart3的区别
- 数据库迁移之从oracle 到 MySQL
- 【Unity入门】编辑器常用视图(转)
- thinkphp 5.0 简明笔记
- zookeeper编程(二)
- Unity中截图只渲染有像素的区域,并且压缩保存到本地
- stm32f207zg uart1配置
- (android高仿系列)今日头条 --新闻阅读器 (三) 完结 、总结 篇
- UNIX环境高级编程第三版源码编译
- Maple 笔记1
- AIDL 编译报can be an out parameter, so you must declare it as in, out or inout原因探究
- 需要跟进的内容
- Java 中得到异常信息
- 欢迎使用CSDN-markdown编辑器
- js页面展示省市联动