cancel
Showing results for 
Search instead for 
Did you mean: 

usart and rs 232 problem

teacha
Associate II
Posted on April 21, 2013 at 12:35

I have a problem ... I want to connect to the terminal via RS 232 converter usb .. code seems to be reasonable but still something is wrong, I can not send anything to the terminal please help.


#include ''stm32f0xx.h''
#include ''stm32f0xx_rcc.h''
#include ''stm32f0xx_gpio.h''
#include ''stm32f0xx_usart.h''
int main(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
//GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
//Configure USART2 pins: Tx and Rx ----------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_Cmd(USART2,ENABLE);
while(1)
{
while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty
USART_SendData(USART2, 0x49); // Send 'I'
}
return 0;
}

#uart #usart #rs232
5 REPLIES 5
Posted on April 21, 2013 at 13:30

The STM32 does not output RS232 compatible voltages, you would need a level converter, or USB-to-CMOS Serial adapter.

If you have a scope, check if you have a signal at the TX pin.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
xtian
Associate II
xtian
Associate II
Posted on April 22, 2013 at 06:37

Hi Wil,

1. try to check a loopback on your USB to serial converter, short the TX and RX Pin, then check on your application or terminal.

2. check if you have the same baudrate,

3.check if you have the correct configuration on the system_stm32f0xx(or if you are using the default from ST ignore this line)

hope this helps

Posted on April 22, 2013 at 08:15

''as clive1 have said.. you have to use a level converter to connect it to pc serial''

 

True - see

http://e2e.ti.com/support/microcontrollers/msp430/f/166/p/70791/804aspx804368

But, instead of connecting to the PC's serial port (even assuming it has one), I would suggest using something like this instead:

http://www.ftdichip.com/Products/Cables/USBTTLSerial.htm

Take care to select the correct version - both 3V and 5V options are available.

This gives a logic-level connection direct to the UART - no messing about with RS232 transceivers.

To PC applications, it appears as a standard COM port.

Or this:

0690X000006037CQAQ.jpg

Which is exactly the same, but with only Rx, Tx, and Ground connections.

http://www.ftdichip.com/Products/Cables/RPi.htm

(They call it ''Raspberry Pi'', but that's immaterial - it's just a 3V UART connection)

teacha
Associate II
Posted on April 22, 2013 at 13:38

thanks for help. problem solved! ;)