在利用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);