cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32F4-Discovery] UART4 Problem

regiuliano2009
Associate II
Posted on February 24, 2012 at 12:36

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-wordlengt
40 REPLIES 40
Posted on February 24, 2012 at 13:07

GPIO_PinAFConfig(GPIOC, GPIO_PinSource_10, GPIO_AF_UART4);

GPIO_PinAFConfig( GPIOC, GPIO_PinSource_11, GPIO_AF_UART4);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
regiuliano2009
Associate II
Posted on February 24, 2012 at 14:58

YeP works!!!

Thanks clive1!!!! U save the daY!!!

(to be precise is

GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);

GPIO_PinAFConfig( GPIOC, GPIO_PinSource11, GPIO_AF_UART4);

without underscore)

I see by Putty some data steam appearing but It's not the welcome message...

uint8_t TxBuffer[] = ''\n\rUSART Hyperterminal Interrupts Example: USART-Hyperterminal\

 communication using Interrupt\n\r'';

Is the problem that DATA is uint16 and data uint8??

void USART_SendData ( *  USARTx,

uint16_t  Data 

)

or have I to configure putty in another way?

That's what I see:

àøüpÿÿàpÇüààþüüààðüààðü~üàü~àüüàÇàü~Àüààðàðüüüüüðüàüÿüü~üüààþüàüpÿÿàpÇüàþüüààðüààðü~üàü~àüüàüüüü~Çü~Çüüðü~üüüüüüàü~àüü~øüÇàü~ÿàüàÇàü~Àüààðàðüüüüàø

translation ISO-8859-1:1998 (Latin-1, West Europe)

Thanks in advance

Posted on February 24, 2012 at 16:01

Sorry working from memory. PinSource uses an index, Pin uses a mask.

You might want to check the ODD parity setting, that would give you weird characters if the terminal is configured for 8N1.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
regiuliano2009
Associate II
Posted on February 24, 2012 at 16:19

no problem clive1 for pinsource

back to problem, If I try to send ''a''  (TXBuffer[]=''a'') the response to terminal is ü    

what's wrong?

I double checked and  my configuration is

  /* 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

I can't understand

regiuliano2009
Associate II
Posted on February 24, 2012 at 16:40

then if I send ''ab'' the response is

üpÀü

?

Posted on February 24, 2012 at 16:54

If it's not the 8O2 rather than 8N1, then perhaps the baud rate is set up wrong.

Consider how the code is being compiled. The STM32F4-Discovery board has a different crystal speed for HSE than the library default. I think you want 8 MHz, not 25 MHz.

Check the crystal speed in the IDE, and the value of HSE_VALUE

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
regiuliano2009
Associate II
Posted on February 24, 2012 at 17:37

thx clive1

I changed PLL_M value but the result is the same

üpÀü @25Mhz

üpÀü @8Mhz

I don't know where else to look

I'll send you my source files... I'll hope it's help.I'm using Atollic True Studio lite

Thanks in advance

________________

Attachments :

src.rar : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I03h&d=%2Fa%2F0X0000000bTS%2F9M3pHzW3WhVxeYiORQ3mhfylrOfc0VakkGoJvC5nmSg&asPdf=false
Posted on February 25, 2012 at 04:54

Well nothing looks to be hideously amiss, I guess at this point I'd be tempted to have it send a continuous stream of characters, 'U' being a particularly clever one, and measure/confirm the bit timing on a scope.

I might also try RealTerm, and try without parity.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
regiuliano2009
Associate II
Posted on February 27, 2012 at 11:23

Dear Clive1,

I have performed the test you have

suggested

.

I have tried with and without parity but nothing change...

I post u some realTerm images (thanks for RT!!!)

(->Can't upload images... I put on Attach)

As u can see there is an ERROR bit! So I think that the problem is il my FTDI UM232r CHIP that can't handle the communication because the STM32 seems working good

I post also a screenshot of PC10 pin of my oscilloscope

I freeze the image of stream of U.

It's seems work. The output values are:

Vpeak-peak 3V

Period 659us

Freq 1,51 kHz

baud= 8bit/2,5ms=3200 ( possible??)

Is a problem that Vinput of 3V and not 3,3V for FTDI chip?

Thanks again!

________________

Attachments :

UART.rar : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I06L&d=%2Fa%2F0X0000000bTR%2F4z5H.V7ZA3AXpr57yQVcV_eoJyBqQk1ZwbqBiyaMod4&asPdf=false