cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 USART2 CAN'T SEND DATA

dnzatlhn91
Associate II
Posted on August 08, 2016 at 08:42

Hi all,

I've built USART2 connection with using none-flow-control via rs485 through my pc. Sending data from my pc to stm32f103 is working correctly however, i can't send any data from stm32 to my pc.

Do you have any idea about that question ?

#stm32-usart2
7 REPLIES 7
troy1818
Senior
Posted on August 08, 2016 at 11:57

Seriously ? Is this really the only information you are planning to give us ?

Not everyone got a crystal ball you know.

jpeacock23
Associate III
Posted on August 08, 2016 at 13:36

The first place to look is how the transceiver is controlled.  Assuming this is half duplex, single wire pair, how to you determine when the STM32 can turn on it's transmitter, and when does the PC end turn it's transmitter off?  This is not a trivial matter; synchronizing both ends of an RS-485 bus requires a robust protocol to define send/receive windows and good error recovery if something doesn't work.

If both ends have the transmitter on you aren't going to receive anything at the PC end, which fits your extremely brief description.  Use a scope to make sure the PC transmitter is off before turning on the STM32 transmitter.

Are both ends of the cable properly terminated?

  Jack Peacock

dnzatlhn91
Associate II
Posted on August 09, 2016 at 12:21

Hello Jack,

Thanks for these informations. I've checked my connections, both cables are terminted properly. Seems that I gotta poblem while activating transmitting mode on STM32-side. Because there is no activation via RTS pin which is goes through transmitter on STM32-side.  Do you have any suggestion to do? 

dnzatlhn91
Associate II
Posted on August 09, 2016 at 12:38

Hello again Jack,

In addition, I've tried to activate RTS pin manually with codes given in below before try to sending data, but can't activate this pin.

// rcc init
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1, ENABLE);
 
 


//init codes
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//set
GPIO_SetBits(GPIOA, GPIO_Pin_1);
//reset
GPIO_SetBits(GPIOA, GPIO_Pin_1);

dnzatlhn91
Associate II
Posted on August 09, 2016 at 12:52

And the USART2 cofiguration codes for trying to activate RTS manually:

void USART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
S2E_Packet *value = get_S2E_Packet_pointer();

RingBuffer_Init(&rxring2, rxbuff2, 1, UART_RRB_SIZE);
RingBuffer_Init(&txring2, txbuff2, 1, UART_SRB_SIZE);

NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

GPIO_InitStructure.GPIO_Pin = USART2_TX ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = USART2_RTS;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = USART2_RX | USART2_CTS;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 19200;
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_ClockInitStruct.USART_Clock = USART_Clock_Disable;
USART_ClockInitStruct.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStruct.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStruct.USART_LastBit = USART_LastBit_Disable;

USART_ClockInit(USART2, &USART_ClockInitStruct);

USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

USART_Cmd(USART2, ENABLE);
}

Walid FTITI_O
Senior II
Posted on August 09, 2016 at 17:05

Hi dtraveller, 

I recommend to check the ''HyperTerminal_HwFlowControl'' example in

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32054.html

You compare the code there with you own code to identify what you have missed if that is related to software.

Th example's path: STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\USART\HyperTerminal_HwFlowControl

-Hannibal-

dnzatlhn91
Associate II
Posted on August 13, 2016 at 11:22

Hi all,

I've completed my code with manual RTS controlling.Thanks for your help.