cancel
Showing results for 
Search instead for 
Did you mean: 

UART connection

explorinova
Associate
Posted on March 07, 2012 at 10:13

I wanted to

use the

UART port

but can not find

any information

to use this port

,

the port

only appears to

USART

, does anyone

can give me

some tips

how you can

connect the

stm32f4discovery

to establish

contact with

this type of

port (

UART

)

#espn
5 REPLIES 5
ronandouguet
Associate II
Posted on March 07, 2012 at 11:24

Hi,

Here an example to configure and use UART 3 :

/**************************************************************************
* @descr Initialise UART3 - RX:PD9 et TX:PD8
* @param None
* @retval None
*************************************************************************/
void
UART3Init(
void
)
{
USART_InitTypeDef UART3_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable USART3 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
/* Connect PD8 and PD9 pins to AF */
GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
/* Configure USART3 Tx (PD8) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init( GPIOD, &GPIO_InitStructure );
/* Configure USART3 Rx (PD9) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init( GPIOD, &GPIO_InitStructure );
/* Initialise Structure UART3 */
UART3_InitStructure.USART_BaudRate = 9600;
UART3_InitStructure.USART_WordLength = USART_WordLength_8b;
UART3_InitStructure.USART_StopBits = USART_StopBits_1;
UART3_InitStructure.USART_Parity = USART_Parity_No;
UART3_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
UART3_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Initialise UART3 */
USART_Init(USART3,&UART3_InitStructure);
/* Enable the interrupt Rx UART3 */
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
/* Enable the UART3 */
USART_Cmd( USART3, ENABLE );
}
/**************************************************************************
* @descr Envoie d'un caractere via l'UARTx
* @param USARTx definie l'uart à utiliser (1,2,3,4,5,6)
* @param Data caractere à transferer
* @retval None
*************************************************************************/
void
USART_SendChar(USART_TypeDef* USARTx, unsigned 
char
Data)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
/* Transmit Data */
USARTx->DR = (Data & (uint16_t)0x01FF);
}
/**************************************************************************
* @descr Envoie d'une chaine de caracteres via l'UARTx
* @param USARTx definie l'uart à utiliser (1,2,3,4,5,6)
* @param s chaine de caracteres à transferer
* @retval None
*************************************************************************/
void
USART_SendString(USART_TypeDef* USARTx, 
char
*s)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
while
(*s)
{
while
(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET);
USART_SendData(USARTx, *s++);
}
}

Posted on March 07, 2012 at 18:57

I wanted to

 

use the

 

UART port

 

but can not find

 

any information

 

to use this port

,

 

the port

only appears to

 

USART

, does anyone

 

can give me

 

some tips

 

how you can

 

connect the

stm32f4discovery

 

to establish

 

contact with

 

this type of

 

port (

UART

)

The easiest way to get serial to a PC is via a USB-to-CMOS Serial chip/cable from the likes of FTDI, Silicon Labs or Prolific. Basically hook up TX, RX and GND, to a USART of your choice. USART3 would be recommended, use the pins supported by the boot loader.

To connect to RS232 level serial, you'll need a MAX232 type device to buffer the voltages.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
explorinova
Associate
Posted on March 12, 2012 at 12:30

but I

'm

trying to communicate with

one

Wifi

module

that has only

one

UART port

for communication

and I am not

able to transmit.

 

zaurozavr
Associate II
Posted on March 12, 2012 at 14:30

Any USART port can work as UART if you add

USARTX_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
 in port initialization.
 BTW some WIFI modules require USARTfor the high speed only (> 115200).
 

Posted on March 12, 2012 at 14:54

but I

'm

trying to communicate with

one

Wifi

module

that has only

one

UART port

for communication

and I am not

able to transmit.

Unfortunately your posts don't contain enough specific detail, and I don't have time to guess what might be wrong. None of us know what you are doing, you have to explain in more detail.

What module?

How's it connected?

What pins?

What USART?

How's the software configured?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..