|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-1-28 22:23:52
|
显示全部楼层
我使用的库是2.0.1版本的,自己的程序如下:
============================================
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
......
============================================
从stm32f10x_usart.h文件中摘录出来的定义:
/* USART Word Length ---------------------------------------------------------*/
#define USART_WordLength_8b ((u16)0x0000)
#define USART_WordLength_9b ((u16)0x1000)
/* USART Parity --------------------------------------------------------------*/
#define USART_Parity_No ((u16)0x0000)
#define USART_Parity_Even ((u16)0x0400)
#define USART_Parity_Odd ((u16)0x0600)
......
=================================================
从stm32f10x_usart.c里边的USART_Init函数中找出来的:
/*---------------------------- USART CR1 Configuration -----------------------*/
tmpreg = USARTx->CR1;
/* Clear M, PCE, PS, TE and RE bits */
tmpreg &= CR1_CLEAR_Mask;
/* Configure the USART Word Length, Parity and mode ----------------------- */
/* Set the M bits according to USART_WordLength value */
/* Set PCE and PS bits according to USART_Parity value */
/* Set TE and RE bits according to USART_Mode value */
tmpreg |= (u32)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
USART_InitStruct->USART_Mode;
/* Write to USART CR1 */
USARTx->CR1 = (u16)tmpreg;
=======================================================================
下面是从数据手册里边摘出来的:
![](http://cache.amobbs.com/bbs_upload782111/files_25/ourdev_530223.JPG)
(原文件名:1.JPG)
![](http://cache.amobbs.com/bbs_upload782111/files_25/ourdev_530224.JPG)
(原文件名:2.JPG)
============================================
从上面这些,应该可以清楚的看出,我的程序已经将M设为0,PCS设为1,PS设为0,正是7位数据,偶校验,实际上的运行效果就是那个串口接收中断里边收到的字节最高位时不时的会变成1,具体啥规律没注意看过。
下面就是2.0.1库里边接收串口数据的函数。
/*******************************************************************************
* Function Name : USART_ReceiveData
* Description : Returns the most recent received data by the USARTx peripheral.
* Input : - USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* - USART1, USART2, USART3, UART4 or UART5.
* Output : None
* Return : The received data.
*******************************************************************************/
u16 USART_ReceiveData(USART_TypeDef* USARTx)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
/* Receive Data */
return (u16)(USARTx->DR & (u16)0x01FF);
}
上面全部的代码都来自于2.0.1的库。
所以,这个是不是要& 0x7F的问题我到现在还是无解呢。 |
|