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-02-27 04:52 AM
I look at the PC11 the IN_PIN of UART4 and FTDIchip is send data at 9600. So it's my discovery that has an different baud
in attach the character U in PC11 (it as the right baud) so, How can I change the baud of stm32? Thank in advance! ________________ Attachments : OSC_IN_U.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzyN&d=%2Fa%2F0X0000000bTQ%2Fq06VUTLaGtqU6K0guhSQMnQisbCq8iFMuuQKnsKPsJw&asPdf=false2012-02-27 07:03 AM
Try :
USART_InitStructure.USART_BaudRate = 9600 * 25 / 8;2012-02-27 08:28 AM
I've tried the value you suggest but still no working.... I've tried other values like 2,1875 or 2,8 but still garbage character....
I used USART_DIV=fsk (=168Mhz)/(8*TXBaud) Which is the right formula? that's my discovery system setting * 5. This file configures the system clock as follows: *============================================================================= *============================================================================= * Supported STM32F4xx device revision | Rev A *----------------------------------------------------------------------------- * System Clock source | PLL (HSE) *----------------------------------------------------------------------------- * SYSCLK(Hz) | 168000000 *----------------------------------------------------------------------------- * HCLK(Hz) | 168000000 *----------------------------------------------------------------------------- * AHB Prescaler | 1 *----------------------------------------------------------------------------- * APB1 Prescaler | 4 *----------------------------------------------------------------------------- * APB2 Prescaler | 2 *----------------------------------------------------------------------------- * HSE Frequency(Hz) | 8000000 *----------------------------------------------------------------------------- * PLL_M | 8 *----------------------------------------------------------------------------- * PLL_N | 336 *----------------------------------------------------------------------------- * PLL_P | 2 *----------------------------------------------------------------------------- * PLL_Q | 7 *----------------------------------------------------------------------------- * PLLI2S_N | NA *----------------------------------------------------------------------------- * PLLI2S_R | NA *----------------------------------------------------------------------------- * I2S input clock | NA *----------------------------------------------------------------------------- * VDD(V) | 3.3 *----------------------------------------------------------------------------- * High Performance mode | Enabled *----------------------------------------------------------------------------- * Flash Latency(WS) | 5 *----------------------------------------------------------------------------- * Prefetch Buffer | OFF *----------------------------------------------------------------------------- * Instruction cache | ON *----------------------------------------------------------------------------- * Data cache | ON *----------------------------------------------------------------------------- * Require 48MHz for USB OTG FS, | Enabled * SDIO and RNG clock | *----------------------------------------------------------------------------- *=============================================================================2012-02-27 08:52 AM
Given the prescaler, surely the formula would be based from a 42 MHz source? The STM32F4 complicated slightly by if 8 or 16-bit oversampling is required.
Any way, a disparity in the desired baud rate is almost universally a result of the software thinking the physical clock is something different than it is.2012-02-27 10:01 AM
If you do not defined HSE_VALUE for the proper crystal freq it gets the default value of 25000000 Hz, irrelevant to the selected board (f.e. Discovery), see lines 90..93 in the Libraries/Device/STM32F4xx/Include/stm32f4xx.h (meaning Project Explorer).
The best way to declare the proper frequency is to set HSE_VALUE globally in Atollic IDE:
Project->Poperties->C/C++ General-> Paths and Symbols-> #SymbolsPress Add.. btn, then type HSE_VALUE and in the next line type 8000000 (for Discovery).
2012-02-27 09:39 PM
hi,
i am using stm32f4 discovery. i am working on interrupt based uart. i am having a problem when sending data to pc through uart. i have looped back data in interrupt. for example i send specific amount of bytes to the controller from pc and it loops it back. if i send 15 bytes at a time there is 0% error in transmission but if i send more than 15 bytes there controller is missing some bytes where there can be an error?2012-02-28 01:50 AM
Dear clive1 e zaurozavr,
I finally get the UART working!!! I have to set the HSE_VALUE as zaurozavr said! Thanks for the support :) see u soon2012-02-28 05:01 AM
i am using stm32f4 discovery. i am working on interrupt based uart.
i am having a problem when sending data to pc through uart.
i have looped back data in interrupt.
for example i send specific amount of bytes to the controller from pc and it loops it back.
if i send 15 bytes at a time there is 0% error in transmission
but if i send more than 15 bytes there controller is missing some bytes
where there can be an error? Without the code you're asking us all to guess, I suspect you fail to buffer the data properly, or check the empty status of the USART. The error is in your code, want specific identification you'll need to post it.
2012-02-29 08:20 AM
During these days I have study the clock tree of Discovery and EVAL. The first has a fixed 8Mhz clock and the other a 25Mhz external clock.
The EVAL manual on page said '' 25 MHz crystal for ethernet PHY with socket. It can be removed when clock is provided by MCO pin of the MCU''. Can I use the clock from MCO (168MHz ?) of my STM32F4 on my discovery? And if yes, haw can I do? Thanks in advance2012-02-29 09:11 AM
Perhaps this would be better asked in a separate thread, but there is no active moderation or thread management here.
The MCO pin(s) are limited to 100 MHz, you can prescale the source clocks to get below that. From RM00905.2.10 Clock-out capabilityTwo microcontroller clock output (MCO) pins are available:
â—� MCO1
You can output four different clock sources onto the MCO1 pin (PA8) using the
configurable prescaler (from 1 to 5):
– HSI clock
– LSE clock
– HSE clock
– PLL clock
The desired clock source is selected using the MCO1PRE[2:0] and MCO1[1:0] bits in
the RCC clock configuration register (RCC_CFGR).
â—� MCO2
You can output four different clock sources onto the MCO2 pin (PC9) using the
configurable prescaler (from 1 to 5):
– HSE clock
– PLL clock
– System clock (SYSCLK)
– PLLI2S clock
The desired clock source is selected using the MCO2PRE[2:0] and MCO2 bits in the
RCC clock configuration register (RCC_CFGR).
For the different MCO pins, the corresponding GPIO port has to be programmed in alternate function mode.
The selected clock to output onto MCO must not exceed 100 MHz (the maximum I/O
speed).
If you want 25 or 50 MHz outputs you'd have to pick the input crystal/oscillator and PLL settings to get there.