cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L Usart half duplex

sanjib
Associate III
Posted on March 16, 2015 at 12:02

Hi

Can anybody say me how to configure for USARt half duplex in stm32l15cb  . I have configured as I configured for stm32f030(working USART half duplex) but it did not work what are the changes between stm32f030 and stm32l15cb 
8 REPLIES 8
Posted on March 16, 2015 at 17:16

@verbatim
===============================================================================
##### Half-duplex mode function #####
===============================================================================
[..] This subsection provides a set of functions allowing to manage the USART
Half-duplex communication.
[..] The USART can be configured to follow a single-wire half-duplex protocol
where the TX and RX lines are internally connected.
[..] USART Half duplex communication is possible through the following procedure:
(#) Program the Baud rate, Word length, Stop bits, Parity, Mode transmitter
or Mode receiver and hardware flow control values using the USART_Init()
function.
(#) Configures the USART address using the USART_SetAddress() function.
(#) Enable the USART using the USART_Cmd() function.
(#) Enable the half duplex mode using USART_HalfDuplexCmd() function.
-@- The RX pin is no longer used.
-@- In Half-duplex mode the following bits must be kept cleared:
(+@) LINEN and CLKEN bits in the USART_CR2 register.
(+@) SCEN and IREN bits in the USART_CR3 register.
@endverbatim

Assume there isn't an army of people to collate that for you, present a clean/clear/concise example of where you have the half-duplex code for the L1 now, and describe how it doesn't work. ie what you've tested, what you expected, and what you saw on a scope.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on March 27, 2015 at 14:44

I have configure as u suggested but still toggling doesn't happen between transmit and receives.

I have done the configuration in the following away

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(USART1, &USART_InitStructure);

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    USART_Cmd(USART1, ENABLE);

    USART_HalfDuplexCmd(USART1, ENABLE);

    USART1->CR2 &=0XB7FF; // bit 11 and bit 14 must be clear CLKEN and LINEN bit

    USART1->CR3 &=0XFFBD; // bit 1 and 5 clear IREN and SCEN

    /* Enable the USARTx Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 11;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

But still not working WHat wrong I am doing . I didn't understand set adress do I need to configure it ? I am having a two board half duplex communication

Posted on March 27, 2015 at 17:22

But still not working what wrong I am doing.

You'll need to create some clean unit tests. It might not be a configuration issue, you might have to manage the transition back and forth. Or find some people with direct half-duplex, smart-card or RS485 type, implementations on the L1 platform. Pick a board others might have, like an L1-DISCO.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sanjib
Associate III
Posted on April 01, 2015 at 12:23

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6gx&d=%2Fa%2F0X0000000btM%2FTNIMQe720UOuMlyvBClEACPulAwhwLGecRdjskK.rUM&asPdf=false
sanjib
Associate III
Posted on April 02, 2015 at 06:53

Any idea

sai
Associate II
Posted on November 11, 2015 at 15:41

Did you figure out what was the issue? Because I am facing a similar problem now with L053

jpeacock
Associate III
Posted on November 11, 2015 at 22:07

In half duplex you must wait for the final TX byte to shift out completely before turning around the line to receive.  After the last byte is sent disable the TXE interrupt, but enable TC interrupt, not RXNE.  After the TC interrupt occurs disable it and then enable RXNE.  That extra gap in time allows the last byte to finish.

UARTs are buffered.  Writing to TX does not mean the byte has arrived at the destination, only that it's queued to be sent.  That's why the TC interrupt is necessary.

  Jack Peacock

sai
Associate II
Posted on November 13, 2015 at 17:44

Thank you very much for your answer!

But I am receiving before transmitting and I am using Polling method!

So, I poll and receive the data, even the last byte. After that, I switch to Transmitting. However, I am unable to transmit the data. Is it possible to do all this using polling method with the HAL drivers?