2016-08-07 11:42 PM
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-usart22016-08-08 02:57 AM
Seriously ? Is this really the only information you are planning to give us ?
Not everyone got a crystal ball you know.2016-08-08 04:36 AM
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
2016-08-09 03:21 AM
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?2016-08-09 03:38 AM
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);
2016-08-09 03:52 AM
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);
}
2016-08-09 08:05 AM
Hi dtraveller,
I recommend to check the ''HyperTerminal_HwFlowControl'' example in 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-2016-08-13 02:22 AM
Hi all,
I've completed my code with manual RTS controlling.Thanks for your help.