cancel
Showing results for 
Search instead for 
Did you mean: 

STM8 UART1 in half-duplex single-wire mode, switching between RX and TX

Kmax18
Senior

I am using a NUCLEO-S8208RB to develop UART1 communication in half-duplex, single-wire mode. The device receives messages (packets of bytes) using the UART1_IT_RXNE_OR interrupt. The next step would be to transmit a byte packet in response, without an interrupt. That does not work. I suspect the UART1_TX configuration is wrong.

* IDE: STVD with COSMIC compiler and STVP.

* STM8 Standard Peripheral Library.

UART1 configuration code (this works):

UART1_DeInit();
UART1_Init((uint32_t)UART1_BAUDRATE, UART1_WORDLENGTH, UART1_STOPBITS, UART1_PARITY, UART1_SYNCMODE, UART1_MODE_TXRX_ENABLE);
UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
UART1_HalfDuplexCmd(ENABLE);
enableInterrupts();

The UART1_RX interrupt call function uses this code snippets:

void UART1_RX_Handler_Callback()
{
  uart1RxData_u8 = UART1_ReceiveData8();
  ...
  UART1_ITConfig(UART1_IT_RXNE_OR, DISABLE);
}

The following code for UART1_TX does not work. It 'hangs', likely due to wrong UART1 register settings. Please comment. Thank you!

void UART1_TransmitPacket8()
{
  uint8_t nBytesToSend = (uint8_t) PACKET_MAX_LEN;
  TxCounter1 = (uint8_t) 0;
  while (nBytesToSend > 0)
  {   
    while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET)
    { } 
    UART1_SendData8(uart1_TxBuffer_u8[TxCounter1]);
    nBytesToSend--;
    TxCounter1++;        
  }
 
  while (UART1_GetFlagStatus(UART1_FLAG_TC) == RESET)
  { }
}

2 REPLIES 2
AA1
Senior III

UART1_SYNCMODE?

Mode should be asynchronous.

Yes, asynchronous mode is on. Thanks you.