用户登录
用户注册

分享至

usartwordlength9b

  • 作者: 笔描相思一墨点红尘
  • 来源: 51数据库
  • 2020-04-21

1.STM32串口有第9位设置么

USART_InitStructure.USART_BaudRate = 9600;

USART_InitStructure.USART_WordLength = USART_WordLength_9b;

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_InitStructure.USART_Clock = USART_Clock_Disable;

USART_InitStructure.USART_CPOL = USART_CPOL_Low;

USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;

USART_InitStructure.USART_LastBit = USART_LastBit_Disable;

/* Configure USART1 */

USART_Init(USART1, &USART_InitStructure);

/* Enable the USART1 */

USART_Cmd(USART1, ENABLE);

/* Set the USART1 Address */

USART_SetAddress(USART1, 0x1);

请问上面一句是否就是设置USART1的第9位,就是地址码

如果我要把地址位置0,是否就是USART_SetAddress(USART1, 0x0);

2.USART

在stm32库中这是一个关于串口的结构体名

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;

解释如下:

uint32_t USART_BaudRate

This member configures the USART communication baud rate. The baud rate is

computed using the following formula:

IntegerDivider = ((PCLKx) / (16 * (USART_InitStruct->USART_BaudRate)))

FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5

在文件stm32f10x_usart.h第52行定义。

uint16_t USART_HardwareFlowControl

Specifies wether the hardware flow control mode is enabled or disabled. This

parameter can be a value of USART_Hardware_Flow_Control

在文件stm32f10x_usart.h第73行定义。

uint16_t USART_Mode

Specifies wether the Receive or Transmit mode is enabled or disabled. This

parameter can be a value of USART_Mode

在文件stm32f10x_usart.h第70行定义。

uint16_t USART_Parity

Specifies the parity mode. This parameter can be a value of USART_Parity

注解:

When parity is enabled, the computed parity is inserted at the MSB position

of the transmitted data (9th bit when the word length is set to 9 data bits; 8th

bit when the word length is set to 8 data bits).

在文件stm32f10x_usart.h第63行定义。

uint16_t USART_StopBits

Specifies the number of stop bits transmitted. This parameter can be a value

of USART_Stop_Bits

在文件stm32f10x_usart.h第60行定义。

uint16_t USART_WordLength

Specifies the number of data bits transmitted or received in a frame. This

parameter can be a value of USART_Word_Length

在文件stm32f10x_usart.h第57行定义。

3.请教STM32 + ST8024 读卡问题

首先确定电路连接,stm32的USART3_CK(PB12)连接到接触式IC卡的CLK端(触点4),stm32的USART3_TX(PB10)连接到接触式IC卡的IO端(触点3),然后stm32选一个GPIO作为输出连接到接触式IC卡的RST端(触点5)。

ic卡的vcc和gnd当然也是要接好的了。然后是程序设计,1,设置时钟,关键的有三个地方,A,在设置系统时钟为72M之后, [cpp] view plaincopyRCC_PCLK1Config(RCC_HCLK_Div2); [cpp] view plain copyRCC_PCLK1Config(RCC_HCLK_Div2); 设置PCLK1频率为36MB,[cpp] view plaincopyRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); [cpp] view plain copyRCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); 使能GPIOB总线时钟,即USART3的端口所在的IO;并使能复用时钟。

C,[cpp] view plaincopyRCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); [cpp] view plain copyRCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); 使能USART3总线时钟。2,设置IO, [cpp] view plaincopyGPIO_InitTypeDef GPIO_InitStructure; /* Configure USART3 CK(PB.12) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = SAM0_CLK; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SAM0_Port, &GPIO_InitStructure); /* Configure USART3 Tx (PB.10) as alternate function open-drain */ GPIO_InitStructure.GPIO_Pin = SAM0_IO; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(SAM0_Port, &GPIO_InitStructure); /* Configure Smartcard Reset */ GPIO_InitStructure.GPIO_Pin = SAM0_RST; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(SAM0_Port, &GPIO_InitStructure); [cpp] view plain copyGPIO_InitTypeDef GPIO_InitStructure; /* Configure USART3 CK(PB.12) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = SAM0_CLK; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(SAM0_Port, &GPIO_InitStructure); /* Configure USART3 Tx (PB.10) as alternate function open-drain */ GPIO_InitStructure.GPIO_Pin = SAM0_IO; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(SAM0_Port, &GPIO_InitStructure); /* Configure Smartcard Reset */ GPIO_InitStructure.GPIO_Pin = SAM0_RST; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(SAM0_Port, &GPIO_InitStructure); 其中已经定义SAM0_CLK为GPIO_Pin_12,定义SAM0_Port为GPIOB,定义SAM0_RST为GPIO_Pin_11,定义SAM0_IO为GPIO_Pin_10,3,设置USART3[cpp] view plaincopyUSART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure; /* USART Clock set to 3.6 MHz (PCLK1 (36 MHZ) / 10) */ USART_SetPrescaler(USART3, 0x05); /* USART Guard Time set to 16 Bit */ USART_SetGuardTime(USART3, 16); USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate = 9677; USART_InitStructure.USART_WordLength = USART_WordLength_9b; USART_InitStructure.USART_StopBits = USART_StopBits_1_5; USART_InitStructure.USART_Parity = USART_Parity_Even; USART_Init(USART3, &USART_InitStructure); USART_ClockInitStructure.USART_Clock = USART_Clock_Enable; USART_ClockInit(USART3, &USART_ClockInitStructure); /* Enable the USART3 Parity Error Interrupt */ USART_ITConfig(USART3, USART_IT_PE, ENABLE); /* Enable the USART3 Framing Error Interrupt */ USART_ITConfig(USART3, USART_IT_ERR, ENABLE); /* Enable USART3 */ USART_Cmd(USART3, ENABLE); /* Enable the NACK Transmission */ USART_SmartCardNACKCmd(USART3, ENABLE); /* Enable the Smartcard Interface */ USART_SmartCardCmd(USART3, ENABLE); [cpp] view plain copyUSART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure; /* USART Clock set to 3.6 MHz (PCLK1 (36 MHZ) / 10) */ USART_SetPrescaler(USART3, 0x05); /* USART Guard Time set to 16 Bit */ USART_SetGuardTime(USART3, 16); USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate = 9677; USART_InitStructure.USART_WordLength = USART_WordLength_9b; USART_InitStructure.USART_StopBits = USART_StopBits_1_5; USART_InitStructure.USART_Parity = USART_Parity_Even; USART_Init(USART3, &USART_InitStructure); USART_ClockInitStructure.USART_Clock = USART_Clock_Enable; USART_ClockInit(USART3, &USART_。

4.如何设置stm32串口工作在115200

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_No;

USART_InitStructure.USART_HardwareFlowControl =USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx |USART_Mode_Tx;

USART_Init(USART1,&USART_InitStructure);

这个配置网上有的是 随便找个文档都有 把9600改为115200 就成了 其他的配置看手册就明白是做什么用的了

5.stm32串口 波特率如何在线更改

先关闭串口,修改好后开启;正在通信时不可以修改。用个函数,使用固件库

void USART_Config(uint32_t baud)

{

USART_InitTypeDef USART_InitStructure;

USART_Cmd(USART1, DISABLE);

USART_InitStructure.USART_BaudRate =baud

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);

}

uint32_t baud_table[]={2400,4800,9600,115200,~~~~~~~};

定义个波特率表,根据外部触发或外中断 更改索引 用新的波特率值传给baud参数,调用这个函数

6.STM32 串口3 USART3 速度不正确,数据是错误的

我觉得可能不是配置的问题可能是你发送函数写的有问题 我的代码是ok的 void USART3_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure; //使能串口3,PB,AFIO总线 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); //串口时钟配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //开漏输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度 GPIO_Init(GPIOB, &GPIO_InitStructure); RS485_CTL3_L(); //RECEIVE /* B10 USART3_Tx */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //推挽输出-TX GPIO_Init(GPIOB, &GPIO_InitStructure); /* B11 USART3_Rx */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入-RX GPIO_Init(GPIOB, &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_ClockInitStructure.USART_Clock = USART_Clock_Disable; USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low; USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable; USART_ClockInit(USART3, &USART_ClockInitStructure); USART_Init(USART3, &USART_InitStructure); /* Enable the USARTx */ USART_Cmd(USART3, ENABLE); //串口3使用接收中断 USART_ITConfig(USART3,USART_IT_RXNE,ENABLE); }/*************************************************************************************** 名 称: * 功 能: * 参 数: * 返 回 值: ** 修改历史:* 版本 日期 作者 **************************************************************************************/ void USART3_Putc(unsigned char c) { RS485_CTL3_H(); //SEND SysTickDelay(1); USART_SendData(USART3, c); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET ); SysTickDelay(1); RS485_CTL3_L(); //RCV }。

转载请注明出处51数据库 » usartwordlength9b

软件
前端设计
程序设计
Java相关