Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f10x.h"
- #include "stm32f10x_it.h"
- #define USARTy USART2
- #define USARTy_GPIO GPIOD
- #define USARTy_CLK RCC_APB1Periph_USART2
- #define USARTy_GPIO_CLK RCC_APB2Periph_GPIOD
- #define USARTy_RxPin GPIO_Pin_6
- #define USARTy_TxPin GPIO_Pin_5
- typedef enum { FAILED = 0, PASSED = !FAILED} TestStatus;
- #define TxBufferSize (countof(TxBuffer))
- /* Private macro -------------------------------------------------------------*/
- #define countof(a) (sizeof(a) / sizeof(*(a)))
- /* Private variables ---------------------------------------------------------*/
- USART_InitTypeDef USART_InitStructure;
- uint8_t TxBuffer[] = "Buffer Send from USARTy to USARTz using Flags";
- uint8_t RxBuffer[TxBufferSize];
- __IO uint8_t TxCounter = 0, RxCounter = 0;
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void USART_Configuration(void);
- volatile TestStatus TransferStatus = FAILED;
- TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);
- //__IO uint8_t index = 0;
- static __IO uint32_t TimingDelay;
- /* Private function prototypes -----------------------------------------------*/
- void Delay(__IO uint32_t nTime)
- {
- TimingDelay = nTime;
- while(TimingDelay != 0);
- }
- /**
- * @brief Decrements the TimingDelay variable.
- * @param None
- * @retval None
- */
- void RCC_Configuration(void)
- {
- /* Enable GPIO clock */
- RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
- RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE);
- }
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Enable the USART2 Pins Software Remapping */
- GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
- /* Configure USARTy Rx as input floating */
- GPIO_InitStructure.GPIO_Pin = USARTy_RxPin;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
- /* Configure USARTy Tx as alternate function push-pull */
- GPIO_InitStructure.GPIO_Pin = USARTy_TxPin;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(USARTy_GPIO, &GPIO_InitStructure);
- }
- void USART_Configuration(void)
- {
- 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;
- /* Configure USARTy */
- USART_Init(USARTy, &USART_InitStructure);
- /* Enable the USARTy */
- USART_Cmd(USARTy, ENABLE);
- }
- int main(void)
- {
- RCC_Configuration();
- GPIO_Configuration();
- USART_Configuration();
- while (1)
- {
- while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET)
- {
- }
- RxBuffer [1] = (USART_ReceiveData(USARTy));
- while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET)
- {
- }
- USART_SendData(USARTy, RxBuffer[1]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement