cancel
Showing results for 
Search instead for 
Did you mean: 

RN4020 Uart Communication with Stm32L100 Discovery Board

herca.1
Associate II

Hi,

I am trying to communicate RN4020 with my STM32L100 disco board however I could not manage to do it. I can send commands and get AOK and Reboot responses when I try it with an Arduino. I did monitor that Disco can communicate correctly with Arduino. I measured the RX TX signals with an oscilloscope and everything looks fine.

I tried with 9600 BR and 115200 BR. I just get no response from RN4020 rarely I get ERR response from the Bluetooth module. i also tried the hardware flow option still nothing.

Does anyone had a similar issue? I am using Cubemx IDE.

I just copy pasted some pieces from uart setting and the way I am trying to send AT commands.

Thank you.

  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  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_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
 
if(uartHandle->Instance==USART1)
  {
  /* USER CODE BEGIN USART1_MspInit 0 */
 
  /* USER CODE END USART1_MspInit 0 */
    /* USART1 clock enable */
    __HAL_RCC_USART1_CLK_ENABLE();
  
    __HAL_RCC_GPIOA_CLK_ENABLE();
    /**USART1 GPIO Configuration    
    PA9     ------> USART1_TX
    PA10     ------> USART1_RX 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
  /* USER CODE BEGIN USART1_MspInit 1 */
 
  /* USER CODE END USART1_MspInit 1 */
  }
 
//Resp Array
 uint8_t Received[10];
/// I AM trying to send simple strings like
uint8_t SetFlowCtr[]="SR,20000000\r\n";
HAL_UART_Transmit(&huart1, (uint8_t*)SetFlowCtr, sizeof(SetFlowCtr), 100);
 
//Currently I am polling the received bytes
for(int i=0; i<sizeof(Received);i++)
	{
		HAL_UART_Receive(&huart1, &Received[i], 1, 100);
	}

1 ACCEPTED SOLUTION

Accepted Solutions

Use strlen() rather than sizeof(), or use sizeof()-1 to lose the NUL

Transmit function also blocks.​

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

Use strlen() rather than sizeof(), or use sizeof()-1 to lose the NUL

Transmit function also blocks.​

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
herca.1
Associate II

Thank you so much. It works.