标题:
STM32F030C8T6串口例程
[打印本页]
作者:
liweijin66
时间:
2017-11-28 09:44
标题:
STM32F030C8T6串口例程
现在提供STM32F030C8T6串口例程,适合初学上手
单片机源程序如下:
/**
******************************************************************************
* @file USART/USART_Printf/main.c
* @author MCD Application Team
* @version V1.4.0
* @date 24-July-2014
* @brief Main program body
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2014 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"
/** @addtogroup STM32F0xx_StdPeriph_Examples
* @{
*/
/** @addtogroup USART_Printf
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void USART_Config(void);
// 重定义
int fputc(int ch, FILE *f)
{
while (!(USART1->ISR & USART_FLAG_TXE));
USART1->TDR = ch;
return (ch);
}
void USART1_Send_Char(unsigned char c)
{
while(!((USART1->ISR)&USART_FLAG_TXE));
USART1->TDR=c;
}
void USART1_Send_String(char *s )
{
while (*s)
USART1_Send_Char(*s++);
}
void SYSTICK_INIT(void)
{
SysTick_Config(SystemCoreClock / 1000); //Set SysTick Timer for 1ms interrupts
//SysTick_Config(SystemCoreClock / 200); //Set SysTick Timer for 5ms interrupts
//SysTick_Config(SystemCoreClock / 100); //Set SysTick Timer for 10ms interrupts
//SysTick_Config(SystemCoreClock / 10); //Set SysTick Timer for 100ms interrupts
}
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f0xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f0xx.c file
*/
// SYSTICK_INIT();
/* USART configuration */
USART_Config();
USART1_Send_String("Fresh Persimmon all right reserved!\r\n");
printf("USART Printf Example: retarget the C library printf function to the USART\r\n");
printf("ASD=%.3f\r\n",9.88987);
while (1)
{
}
}
/**
* @brief Configure the USART Device
* @param None
* @retval None
*/
void USART_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE );
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
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_Cmd(USART1, ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
STM32F030C8T6串口例程.zip
(487.8 KB, 下载次数: 549)
2017-11-28 10:30 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
hackxt
时间:
2018-7-10 10:33
感谢分享!!!!
作者:
haiqingxiao
时间:
2018-7-19 15:48
下载了,不错,谢谢!!
作者:
笑浅
时间:
2018-10-17 18:21
下载,好东西
作者:
lxiaoxi
时间:
2019-9-26 14:54
感谢分享!!!!
作者:
471097604
时间:
2019-9-26 21:15
正在找这个呢
作者:
esmember
时间:
2019-9-27 08:23
这个可以有,不过想屏蔽一下串口呢。
作者:
MR.Xuan
时间:
2019-10-11 11:28
有空下来看看
作者:
nonplus
时间:
2019-12-30 10:02
感谢分享!!!!
作者:
vivianb
时间:
2019-12-30 15:33
谢谢分享,不错的东西
作者:
GlenXu
时间:
2020-1-19 11:52
感谢分享,学习了!
作者:
mspの心
时间:
2021-6-10 17:38
感谢楼主的分享,部分疑惑解答了
作者:
ddddabv
时间:
2022-5-30 15:47
好用吗?
作者:
LEO_Huang
时间:
2022-6-1 12:03
赞,正在找串口程序。
作者:
阿牛——牛
时间:
2023-1-6 13:38
刚下载了,不错,正在学习中
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1