cancel
Showing results for 
Search instead for 
Did you mean: 

Is it ok if uart communication of vcom_init () is rs-485? (vcom.c)

SMinC.897
Associate

Hi

I use 'PRINTF' and 'AT command' using vcom.c from the I-CUBE-LRWAN source.

And develop in the following situations.

1. UART communication uses RS-232.

2. I use  STM32L082 low-power chip.

3.I use LPUART and NVIC interrupts.

and then, I made the following changes and tested them.

1.change uart port. (usart2 - > usart1)

2.in usart1 port i uses RS-485.

Then PRINTF and AT-command do not work.

Do you have to add other parts to the following sources when using rs-485? Or can you use usart1 as the uart port of lpuart? (See terminal configuration)

void vcom_Init(void)
{
  LL_LPUART_InitTypeDef LPUART_InitStruct;
 
  /*## Configure the UART peripheral ######################################*/
  /* Put the UART peripheral in the Asynchronous mode (UART Mode) */
  /* UART1 configured as follow:
      - Word Length = 8 Bits
      - Stop Bit = One Stop bit
      - Parity = ODD parity
      - BaudRate = 921600 baud
      - Hardware flow control disabled (RTS and CTS signals) */
 
  /*
   * Clock initialization:
   * - LSE source selection
   * - LPUART clock enable
   * - GPIO clocks are enabled in vcom_IoInit()
   */
  LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_HSI);
  UARTX_CLK_ENABLE();
  vcom_IoInit(); /* init vcom */
 
  LPUART_InitStruct.BaudRate = 115200;
  LPUART_InitStruct.DataWidth = LL_LPUART_DATAWIDTH_8B;
  LPUART_InitStruct.StopBits = LL_LPUART_STOPBITS_1;
  LPUART_InitStruct.Parity = LL_LPUART_PARITY_NONE;
  LPUART_InitStruct.TransferDirection = LL_LPUART_DIRECTION_TX_RX;
  LPUART_InitStruct.HardwareFlowControl = LL_LPUART_HWCONTROL_NONE;
 
  if (LL_LPUART_Init(UARTX, &LPUART_InitStruct) != SUCCESS)
  {
    Error_Handler();
  }
 
  /* Configuring the LPUART specific LP feature - the wakeup from STOP */
  LL_LPUART_EnableInStopMode(UARTX);
 
  /* WakeUp from stop mode on start bit detection*/
  LL_LPUART_SetWKUPType(UARTX, LL_LPUART_WAKEUP_ON_STARTBIT);
  //LL_LPUART_SetWKUPType(UARTX, LL_LPUART_WAKEUP_ON_RXNE);
  LL_LPUART_EnableIT_WKUP(UARTX);
 
  LL_LPUART_Enable(UARTX);
  while (LL_LPUART_IsActiveFlag_TEACK(UARTX) == RESET)
  {
    ;
  }
  while (LL_LPUART_IsActiveFlag_REACK(UARTX) == RESET)
  {
    ;
  }
  uart_context.gState = HAL_UART_STATE_READY;
  uart_context.RxState = HAL_UART_STATE_READY;
}
 
void vcom_IoInit(void)
{
  GPIO_InitTypeDef GPIO_InitStruct;
 
  /* UART TX GPIO pin configuration  */
  GPIO_InitStruct.Mode      = GPIO_MODE_AF_PP;
  GPIO_InitStruct.Pull      = GPIO_NOPULL;
  GPIO_InitStruct.Speed     = GPIO_SPEED_FREQ_MEDIUM;
  GPIO_InitStruct.Alternate = UARTX_TX_AF;
 
  HW_GPIO_Init(GPIOA, GPIO_PIN_9/*this point change*/, &GPIO_InitStruct);
 
  /* UART RX GPIO pin configuration  */
  GPIO_InitStruct.Alternate = UARTX_RX_AF;
 
  HW_GPIO_Init(GPIOA, GPIO_PIN_10/*this point change*/, &GPIO_InitStruct);
 
  /*##-3- Configure the NVIC for UART ########################################*/
  /* NVIC for UART */
  NVIC_SetPriority(UARTX_IRQn, 0);
  NVIC_EnableIRQ(UARTX_IRQn);
  
  /* enable RXNE */
  LL_LPUART_EnableIT_RXNE(UARTX);
 
}
 
void vcom_IoDeInit(void)
{
  GPIO_InitTypeDef GPIO_InitStructure = {0};
 
  GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
  GPIO_InitStructure.Pull = GPIO_NOPULL;
 
  HW_GPIO_Init(GPIOA, GPIO_PIN_9/*this point change*/, &GPIO_InitStructure);
 
  HW_GPIO_Init(GPIOA, GPIO_PIN_10/*this point change*/, &GPIO_InitStructure);
}

0690X00000ArQlxQAF.png

0 REPLIES 0