Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f10x.h"
- uint8_t rec = 0;
- /* Private variables ---------------------------------------------------------*/
- USART_InitTypeDef USART_InitStructure;
- /* Private function prototypes -----------------------------------------------*/
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- }
- void RCC_Configuration(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
- }
- void USART_Configuration()
- {
- 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(USART2, &USART_InitStructure);
- USART_Cmd(USART2, ENABLE);
- }
- int main(void)
- {
- RCC_Configuration();
- GPIO_Configuration();
- USART_Configuration();
- while (1)
- {
- /* Loop until the USARTz Receive Data Register is not empty */
- while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET)
- {
- }
- rec = USART_ReceiveData(USART2);
- /* Loop until USARTy DR register is empty */
- while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET)
- {
- }
- USART_SendData(USART2, rec);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement