📄 usart_tr.c
字号:
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : usart_1_2.c
* Author : MCD Tools development Team
* Date First Issued : Oct. 2007
* Description : This code is used for MB672 board test
********************************************************************************
* History:
* May 19, 2008: V1.1
* April 30, 2008: V1.0
* April 16, 2008: V0.2
* March 19, 2008: V0.1
* Oct. 19, 2007: V0.01
********************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "usart_tr.h"
u8 TxBuffer1[] = "Buffer Send from USART1 to USART2 using Flags";
u8 TxBuffer2[] = "Buffer Send from USART2 to USART1 using Flags";
u8 RxBuffer1[TxBufferSize];
u8 RxBuffer2[TxBufferSize];
u8 TxCounter = 0, RxCounter = 0;
//-----------------------------------------------------------------
// USART 1 initialization
// USART 1 on ev board Corresponds to USART 1(1 of 1~5) of MCU
//-----------------------------------------------------------------
u8 USART_Init_Test(void)
{
USART_InitTypeDef USART_InitStructure;
TestStatus status;
/* USART1 and USART2 configuration ------------------------------------------------------*/
/* USART and USART2 configured as follow:
- BaudRate = 230400 baud
- Word Length = 8 Bits
- One Stop Bit
- Even parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
- USART Clock disabled
- USART CPOL: Clock is active low
- USART CPHA: Data is captured on the second edge
- USART LastBit: The clock pulse of the last data bit is not output to
the SCLK pin
*/
USART_InitStructure.USART_BaudRate = 230400;
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_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;
USART_Init(USART1, &USART_InitStructure);
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
USART_Cmd(USART2, ENABLE);
while(TxCounter < TxBufferSize)
{
// Send one byte from USART1 to USART2
USART_SendData(USART1, TxBuffer1[TxCounter++]);
// Loop until the end of transmit
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
// Loop until the USART2 Receive Data Register is not empty
while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET);
// Store the received byte in RxBuffer
RxBuffer1[RxCounter++] = (USART_ReceiveData(USART2) & 0x7F);
}
// Check the received data with the send ones
//TransferStatus = Buffercmp(TxBuffer, RxBuffer, TxBufferSize);
status = Buffercmp(TxBuffer1, RxBuffer1, TxBufferSize);
if(status == 0)
return USART_TEST_FAIL;
else{
TxCounter = 0, RxCounter = 0;
while(TxCounter < TxBufferSize)
{
// Send one byte from USART2 to USART1
USART_SendData(USART2, TxBuffer2[TxCounter++]);
// Loop until the end of transmit
while(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET);
// Loop until the USART2 Receive Data Register is not empty
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
// Store the received byte in RxBuffer
RxBuffer2[RxCounter++] = (USART_ReceiveData(USART1) & 0x7F);
}
// Check the received data with the send ones
//TransferStatus = Buffercmp(TxBuffer, RxBuffer, TxBufferSize);
status = Buffercmp(TxBuffer2, RxBuffer2, TxBufferSize);
if(status == 0)
return USART_TEST_FAIL;
else
return USART_TEST_PASS;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -