cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting TTL-232R to STM32F3DISCOVERY

tonyblake9
Associate II
Posted on May 05, 2017 at 18:44

Hi,

I'm trying to connect a TTL-232R USB-UART Converter to an STM32F3DISCOVERY board. I've connected the TX/RX wires on the TTL-232R to PB10/PB11 on the STM32F3DISCOVERY board. I have the board connected to my laptop over USB.

Do I need to connect the 5V/GND wires on the TTL-232R? Or are these signals already provided by USB?

Any help would be much appreciated.

Cheers,

Tony

#uart #stm32f3-discovery
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on May 09, 2017 at 14:29

Connecting two OUTPUT pins together is going to fail. Read my original response.

The pins and USART are not correctly configured, don't paste STM32F1 code and expect it to work on an STM32F3, the GPIO configuration changed.

Both pins need to be in AF mode, and both must be routed to the USART peripheral. See F3 example

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

View solution in original post

11 REPLIES 11
Posted on May 05, 2017 at 20:15

You'd want to common the grounds.

The TX of the STM32 would need to go to the RX of the TTL-232R

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Tomas DRESLER
Senior II
Posted on May 05, 2017 at 20:15

Hi Tony,

GND needs to be connected in all cases.

5V interconnection from the USB-TTL to Disco normally isn't needed and is delivered by USB cables to both boards independently. You can check presence of +5V by voltmeter, too.

S.Ma
Principal
Posted on May 05, 2017 at 20:18

It really depends on the spec of the cable. Surely the grounds must be common.

Using the ST Link USB plug to power the discovery eliminates the USB 100 or 500mA budget limit worries.

The answer is to try it out without 5V connected... and see what happens. It won't be destructive.

Posted on May 09, 2017 at 13:29

Hi Edison,

I've tried getting data from the UART both with and without the 5V line connected but I'm not having any joy. I've connected my TTL-232R cable to my STM32F3DISCOVERY like so:

TTL-232R wire      STM32F3DISCOVERY pin

5V                                          5V

TX                              PA9 (USART1_TX)

RX                             PA10 (USART1_RX)

GND                                     GND

I've written the following code which I think is fine:

int main(){

   ...

   USART1_Init();

   ...

   while(1){

      ...

      sendData('Testing');

      ...

   }

}

void USART1_Init(void)

{

/* USART configuration structure for USART1 */

USART_InitTypeDef usart1_init_struct;

/* Bit configuration structure for GPIOA */

GPIO_InitTypeDef gpioa_init_struct;

/* Enable clock for USART1, AFIO and GPIOA */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_AHBPeriph_GPIOA, ENABLE);

/* GPIOA PIN9 alternative function Tx */

gpioa_init_struct.GPIO_Pin = GPIO_Pin_9;

gpioa_init_struct.GPIO_Speed = GPIO_Speed_50MHz;

gpioa_init_struct.GPIO_Mode = GPIO_Mode_AF;

GPIO_Init(GPIOA, &gpioa_init_struct);

/* GPIOA PIN10 alternative function Rx */

gpioa_init_struct.GPIO_Pin = GPIO_Pin_10;

gpioa_init_struct.GPIO_Speed = GPIO_Speed_50MHz;

gpioa_init_struct.GPIO_Mode = GPIO_Mode_IN;

GPIO_Init(GPIOA, &gpioa_init_struct);

/* Enable USART1 */

USART_Cmd(USART1, ENABLE);

/* Baud rate 9600, 8-bit data, One stop bit

* No parity, Do both Rx and Tx, No HW flow control

*/

usart1_init_struct.USART_BaudRate = 115200;

usart1_init_struct.USART_WordLength = USART_WordLength_8b;

usart1_init_struct.USART_StopBits = USART_StopBits_1;

usart1_init_struct.USART_Parity = USART_Parity_No ;

usart1_init_struct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

usart1_init_struct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

/* Configure USART1 */

USART_Init(USART1, &usart1_init_struct);

/* Enable RXNE interrupt */

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

/* Enable USART1 global interrupt */

NVIC_EnableIRQ(USART1_IRQn);

}

void sendData(const char *str){

while(*str){

// USART_FLAG_TXE goes HIGH when data is sent

while(USART_GetFlagStatus(USART1,USART_FLAG_TXE) == RESET);

USART_SendData(USART1, *str++);

}

}

Does this all look ok to you? Also, I assume it is ok to connect wires to the underside of the STM32F3DISCOVERY board, i.e. from the 2.54mm pitch pins?

Tony

Posted on May 09, 2017 at 13:59

Hi Tony,

0. seeing you use StdLib, please select proper Alternate Function for the GPIOs by GPIO_PinAFConfig

1. I don't see UART IRQ priority setup

2. you can always try to short Tx and Rx together on each side and see if this HW loopback works

3. the lines must be crossed (Tx->Rx) for both directions

4. if you're unsure, try 330R-1k resistor in series with Tx/Rx lines to prevent short circuit between two Tx lines

5. send oscilloscope snapshot of the lines to the forum to see the level and distortion of the signals

Posted on May 09, 2017 at 14:29

Connecting two OUTPUT pins together is going to fail. Read my original response.

The pins and USART are not correctly configured, don't paste STM32F1 code and expect it to work on an STM32F3, the GPIO configuration changed.

Both pins need to be in AF mode, and both must be routed to the USART peripheral. See F3 example

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tonyblake9
Associate II
Posted on May 09, 2017 at 16:44

Can someone point me to the document that explains how to set up the USART on the STM32F3? I can't find it on the ST website...

Posted on May 09, 2017 at 16:59

Yeah, it's called Examples of the Standard Peripheral Library that you use. Look it up in the directory STM32F30x_DSP_StdPeriph_Lib_V1.2.1.zip\STM32F30x_DSP_StdPeriph_Lib_V1.2.1\Projects\STM32F30x_StdPeriph_Examples\USART

I believe, if you try what me and Clive suggest, you shall be going in 15 minutes top.

Posted on May 09, 2017 at 17:03

Thank you Clive, I'm now successfully receiving uart data using your code