2012-02-24 03:36 AM
Hi all,
I'm searching to get work my UART4 port on my Discovery. I used the USART HyperTerminal_Interrupt example on stdPerif_example and I adapted to DISCOVERY. I see by some LedOn on the program that UART is working and sending interrupt. I manage to have a virtual USB-UART port with UM232R Ftdi but on my Putty nothing appeared I post my code /* 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 = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_2; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(&USART_InitStructure); Function void STM_EVAL_COMInit(USART_InitTypeDef* USART_InitStruct) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIO clock */ //RCC_AHB1PeriphClockCmd(UART4_TX_PIN | UART4_RX_PIN, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //clock a PORTC RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); //clock alla UART4! /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(GPIOC, GPIO_Pin_10, GPIO_AF_UART4); /* Connect PXx to USARTx_Rx*/ GPIO_PinAFConfig( GPIOC, GPIO_Pin_11, GPIO_AF_UART4); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIOC, &GPIO_InitStructure); /* USART configuration */ USART_Init(UART4, USART_InitStruct); /* Enable USART */ USART_Cmd(UART4, ENABLE); } I also add void UART4_IRQHandler(void); to _it.h to manage interrupt _it.c void UART4_IRQHandler(void) { if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) { GPIO_SetBits(GPIOD, GPIO_Pin_14); // accende led /* Read one byte from the receive data register */ RxBuffer[RxCounter++] = (USART_ReceiveData(UART4) & 0x7F); if(RxCounter == NbrOfDataToRead) { /* Disable the UART4 Receive interrupt */ USART_ITConfig(UART4, USART_IT_RXNE, DISABLE); } } if(USART_GetITStatus(UART4, USART_IT_TXE) != RESET) { GPIO_SetBits(GPIOD, GPIO_Pin_13); // accende led /* Write one byte to the transmit data register */ USART_SendData(UART4, TxBuffer[TxCounter++]); if(TxCounter == NbrOfDataToTransfer) { /* Disable the UART4 Transmit interrupt */ USART_ITConfig(UART4, USART_IT_TXE, DISABLE); } } } Where I'm failing? THanks #uart/usart-parity-and-wordlengt2012-03-01 06:44 AM
Ops... sorry for the wrong posting.
Thanks Clive12012-03-14 11:28 PM
2012-03-15 05:21 AM
GPIO_PinAFConfig(GPIOD,GPIO_Pin_11,GPIO_AF_USART3); // CTS
To reiterate what I've said previously, you MUST use the GPIO_PinSource?? values in GPIO_PinAFConfig(). Don't enable/disable the interrupts in the service routine. Don't spin use while() spin loops in interrupts. Use some form of elastic buffering to handle different rates, and the fact different ports may block based on the flow control. Use transmit and CTS interrupts as required. Disable transmit interrupt if no data pending. Handle USART error conditions, identify and clear overrun, etc.
2012-03-16 12:03 AM
2012-03-18 05:09 PM
I am using even parity. To get it to work for 8 databits it was necessary to specify USART_WordLength_9b. The symptom appeard for any character that resulted in the parity bit = 1. Terminal emulators usually treat bits and parity settings independently, whereas the UART/USART_InitStructure has a different idea about that.
2012-09-08 07:37 AM
I have the same problem.
I have copied an uart example from another stm32 board to the stm32discovery boardim trying to send ''\n\r *********************** RTC Hardware Calendar Example ***********************\n\r''but just receiving''÷÷÷÷÷÷÷÷÷÷÷[07][00][00][06][01][00][02]íÿÿ÷÷÷÷÷÷÷÷÷÷÷÷÷÷ôü''the HSE_VALUE is deffo correct#define HSE_VALUE ((uint32_t)8000000)the pc Terminal is setup correct, the code works fine on the other stm32 board (25mhz) cant quite see where its going wrong, definitely seams like a clock speed is set wrong some where.2012-09-08 08:13 AM
Review also the PLL settings in system_stm32f4xx.c, PLL_M is typically set to the crystal frequency so the comparison in the PLL occurs at 1 MHz.
2012-09-08 08:51 AM
yup looks correct, comparing it to other stm32 discovery projects i have downloaded
#define PLL_M 8#define PLL_N 336/* SYSCLK = PLL_VCO / PLL_P */#define PLL_P 2/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */#define PLL_Q 7i also have being playing with a little micro second delay function which runs about twice as fast as it should, timing some where is set wrong. but where!!!2012-09-08 12:11 PM
using all the correct files that came with the discovery example zip projects
the ide is set to 8mhzjust cant see how its going wrong :(2012-09-08 02:53 PM
Are you in a position to scope the pins and confirm bit times, or clocks?
HSE_VALUE can often be defined in the IDE's meta-data and passed to the compiler via the command line options. Other places it often appears are stm32f4xx_conf.h and stm32f4xx.h. Be cognizant of the include path settings and precedents which may cause different files of the same name being pulled in preference to the ones you think are coming in. You might want to inspect the generated code, or have the tool chain output pre-processor data to confirm expected values, etc. Parity in USART output of 8-bits assumes the 9-bit mode is selected. Scaling the baud rate setting might permit you to evaluate if the wrong basis is being applied.