分享

Stm32串口发送字符

 陈春松 2011-07-05
 
 Stm32串口发送字符

2011-01-31 11:10:26|  分类: STM32 |  标签:串口  发送  usart1  stm32  设定   |字号 订阅

设定UART1时钟

设定发送脚功能

串口设置,使能

#include "stm32f10x.h"

void RCC_Configuration(void);

void GPIO_Configuration(void);

void USART_Configuration(void);

unsigned char str[]="A";

int main(void)

{

  RCC_Configuration();

  GPIO_Configuration();

  USART_Configuration();

  USART_SendData(USART1,str[0]);  

  while(1);

}

void RCC_Configuration(void)

{    

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

}

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

  /*只设定了发送*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

}

void USART_Configuration(void)

{

  USART_InitTypeDef USART_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_Tx; /*只设定了发送*/

  USART_Init(USART1 , &USART_InitStructure);

  USART_Cmd(USART1, ENABLE);

}


 
 
 
 
 
 
 
 
 
 
 
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多