单片机接收的数据帧(其中不包括帧头:0x55)
typedef struct
{
unsigned charucIndex; //从器件编号
unsigned charucOprType; //操作类型,读00写01
unsigned charucOprAddr2; //Addr2 地址低位
unsigned charucOprAdd1; //Addr1 地址中间
unsigned charucOprAdd0; //Addr0 地址高位
unsigned charucOprDataLen; //len 数据长度(ucDataBuffer内的数据长度)
unsigned charucXorValue; //Xor 校验数据(异或)
unsigned charucDataBuffer[256]; //DataBuffer 数据
}
/* USARTx configured as follows:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
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_Rx | USART_Mode_Tx;
我定义的串口帧:
帧头0x55+ucIndex+ucOprType+ucOprAddr2+ucOprAdd1+ucOprAdd0+ucOprDataLen+ucXorValue+ucDataBuffer[256])是和UART定义里面的起始位+bit0+bit1+bit2+bit3+bit4+bit5+bit6+bit7(奇偶校验位)+停止位是一码事得一一对应吗?串口设置的是无奇偶校验,而我帧里面定义的是有ucXorValue奇偶校验,bit7(奇偶校验位)就得是我的ucXorValue吗?现在我UART里面设置的是wordlength 8bit这和ucOprDataLen也是一回事吗?而且串口设置有1位停止位,而我帧定义里面似乎没有?
是我搞混了还是这两者无关系呢?很迷惑,高手大神请解惑 |