반응형
Notice
Recent Posts
Recent Comments
Link
Brise
STM32F411RE-nucleo Standard Peripheral UART 예제 본문
반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include "stm32f4xx.h" int main() { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitTypeDef GPIO_InitStruct; GPIO_StructInit(&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_StructInit(&GPIO_InitStruct); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); USART_InitTypeDef USART_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); USART_StructInit(&USART_InitStructure); 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); while(1) { FlagStatus fStatus = USART_GetFlagStatus(USART2, USART_FLAG_RXNE); /* Recv 확인 */ if(fStatus == SET ) { /* 있는 경우 */ uint16_t rData = USART_ReceiveData(USART2); /* 데이터를 받는다 */ while(USART_GetFlagStatus(USART2, USART_FLAG_TXE)==0); /* TX가 가능할 때까지 blocking*/ USART_SendData(USART2, rData); /* 데이터를 보낸다. */ } } } | cs |
반응형
'MCU' 카테고리의 다른 글
STM32F401RE-nucleo CMSIS ADC (0) | 2017.12.07 |
---|---|
STM32F411RE-nucleo UART 데이터 중계 예제 (0) | 2017.12.05 |
STM32F411RE-nucleo Printf 예제 (0) | 2017.12.05 |
STM32F401RE-nucleo CMSIS UART 예제 (0) | 2017.12.05 |
STM32F429-DISC1 디스커버리 보드 BSP와 CubeMX 연동하여 사용하기 (0) | 2017.11.11 |
[STM32CubeMX] STM32F429-DISC0 엔코더값 입력받기(quadrature encoder pulse) -2 (0) | 2017.04.29 |
[STM32CubeMX] STM32F429-disc0 엔코더값 입력받기(quadrature encoder pulse) -1 (0) | 2017.04.28 |
Comments