2012-12-02 10:52 AM
I used example code in here to send and echo char through UART. I connected PB10, PB11 right to RX and TX pin to FT232RL and connect it to USB's PC. On PC I'm using Hyperterminal with the correct baudrate, parity, stopbit. But I ca't send or recieve anything.
I changed the code to send any other character like 'a' or 'h' or 'o' to PC but all I receive is '|'I think the fault is I'm using FT232RL (I test this IC work fine), Do I have to connect PB10, PB11 just to a USB-Serial and no need a MAX232 ??? Sorry I'm new-bieThis is code I coppied// STM32 USART3 (Tx PB.10, Rx PB.11) STM32F4 Discovery - sourcer32@gmail.com /**************************************************************************************/ #include ''stm32f4xx_usart.h'' #include ''stm32f4xx_gpio.h'' #include ''stm32f4xx_rcc.h''void RCC_Configuration(void){ /* --------------------------- System Clocks Configuration -----------------*/ /* USART3 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /* GPIOB clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);} /**************************************************************************************/ void GPIO_Configuration(void){ GPIO_InitTypeDef GPIO_InitStructure; /*-------------------------- GPIO Configuration ----------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Connect USART pins to AF */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);} /**************************************************************************************/ void USART3_Configuration(void){ USART_InitTypeDef USART_InitStructure; /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 19200; 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(USART3, &USART_InitStructure); USART_Cmd(USART3, ENABLE);} /**************************************************************************************/ void Delay(__IO uint32_t nCount){ while(nCount--) { }}int main(void){ RCC_Configuration(); GPIO_Configuration(); USART3_Configuration(); while(1){ if (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) != RESET) // Character Ready { uint16_t ch; ch = USART_ReceiveData(USART3); // Grab it while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART3, ch); // Echo it } #define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE) if (USART_GetFlagStatus(USART3, USART_FLAG_ERRORS) != RESET) // Errors? USART_ReceiveData(USART3); // Clear Them} }The code I edited that I recieved only '|' on hyperterminal while(1){ USART_SendData(USART2, 'h'); // defined in stm32f4xx_usart.h Delay(0x3FFFFF); }2012-12-02 12:50 PM
The FT232RL should interface with 3 or 3.3V CMOS serial directly.
Your problem is more likely that files in your project, or settings within it, are setting the HSE_VALUE to 25000000. The HSE crystal on the F4 Discovery is 8 MHz, so a disparity between the hardware, and the software will result in the baud rate coming out wrong. You could measure the bit timing on the scope, then you'd know what was happening. You also need to wait on the Transmit Register being empty while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART3, 'h');2012-12-02 07:55 PM