AnsweredAssumed Answered

STM32F103 UART1 flow control + bluetooth BT121

Question asked by Daniele Mereu on Aug 1, 2017
Latest reply on Aug 2, 2017 by Daniele Mereu

Hi all,

I've a problem on STM32F103RET6 microcontroller using the UART1 flow control in combination with the Bluegiga BT121 bluetooth chip. I'm using a custom board with these simple hardware configuration:

Hardware configuration

I'm using UART1 with DMA and this is the source code:

static void MX_USART1_UART_Init(void)
{
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 460800;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
      _Error_Handler(__FILE__, __LINE__);
  }
}

void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{

   GPIO_InitTypeDef GPIO_InitStruct;

   if(huart->Instance==USART1)

   {

      /* Peripheral clock enable */

      __HAL_RCC_USART1_CLK_ENABLE();

      /**USART1 GPIO Configuration

      PA9     ------> USART1_TXP

      PA10     ------> USART1_RX

      PA11     ------> USART1_CTS

      PA12     ------> USART1_RTS */

      GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_12;

      GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

      GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11;

      GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

      GPIO_InitStruct.Pull = GPIO_NOPULL;

      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

      /* USART1 DMA Init */

      /* USART1_TX Init */

      hdma_usart1_tx.Instance = DMA1_Channel4;

      hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;

      hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE;

      hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE;

      hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

      hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

      hdma_usart1_tx.Init.Mode = DMA_NORMAL;

      hdma_usart1_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH;

      if (HAL_DMA_Init(&hdma_usart1_tx) != HAL_OK)

      {

         _Error_Handler(__FILE__, __LINE__)}

      }

      __HAL_LINKDMA(huart,hdmatx,hdma_usart1_tx);

      /* USART1_RX Init */

      hdma_usart1_rx.Instance = DMA1_Channel5;

      hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;

      hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;

      hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;

      hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

      hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

      hdma_usart1_rx.Init.Mode = DMA_CIRCULAR;

      hdma_usart1_rx.Init.Priority = DMA_PRIORITY_VERY_HIGH;

      if (HAL_DMA_Init(&hdma_usart1_rx) != HAL_OK)

      {

         _Error_Handler(__FILE__, __LINE__);

      }

      __HAL_LINKDMA(huart,hdmarx,hdma_usart1_rx);

      /* USART1 interrupt Init */

      HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);

      HAL_NVIC_EnableIRQ(USART1_IRQn);

   }

}

The problem is that I can only send data but not receive!
I did several tests:
1.   add pull-up resistors
2.   change the transmission speed
3.   try with a different hardware: ST Inemo + BT121 evaluation board
but the only solution I found to be able to send messages was to disable the flow control
.


So, my question is: does anyone have any idea why it does not work? What am I doing wrong?

 

Many thanks in advance

Outcomes