STM32固件函数库中文版之USART 弊端

在利用USART 结构体进行初始化操作时,

根据函数库提供的例子进行初始化时候
compiling main.c...

..\User\main.c(73): error: #134: expected a field name

..\User\main.c(78): error: #136: struct "<unnamed>" has no field "USART_Clock"

..\User\main.c(79): error: #136: struct "<unnamed>" has no field "USART_CPOL"

..\User\main.c(80): error: #136: struct "<unnamed>" has no field "USART_CPHA"

..\User\main.c(81): error: #136: struct "<unnamed>" has no field "USART_LastBit"

..\User\main.c - 5 Error(s), 0 Warning(s).

通过查看相关头文件 时候 发现

typedef struct
{
uint32_t USART_BaudRate;
uint16_t USART_WordLength;
uint16_t USART_StopBits;
uint16_t USART_Parity;
uint16_t USART_Mode;
uint16_t USART_HardwareFlowControl;
} USART_InitTypeDef;


typedef struct
{
uint16_t USART_Clock;
uint16_t USART_CPOL;
uint16_t USART_CPHA;
uint16_t USART_LastBit;
} USART_ClockInitTypeDef;

中文提供的初始化 例子如下
{
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_Parity_Odd;
USART_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_RTS_CTS;
USART_InitStructure.USART_Mode = USART_Mode_Tx|USART_Mode_Rx;

USART_InitStructure.USART_Clock = USART_Clock_Disable;
USART_InitStructure.USART_CPOL = USART_CPOL_High;
USART_InitStructure.USART_CPHA = USART_CPHA_1Edge;
USART_InitStructure.USART_LastBit = USART_LastBit_Enable;

USART_Init(USART1,&USART_InitStructure);
}


根据ST英文库函数提供的例子
Example:
/* The following example illustrates how to configure the USART1 */

USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Odd;
USART_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_RTS_CTS;
USART_InitStructure.USART_Mode = USART_Mode_Tx I USART_Mode_Rx;
USART_Init(USART1, &USART_InitStructure);


3f567a1ee09507d7f8ce273014d68fd5.jpeg

92ec07ebc8d55923e8b02e52aebe6407.jpeg

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值