2019-12-25 08:53 AM
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);
}
Solved! Go to Solution.
2019-12-25 09:56 AM
Use strlen() rather than sizeof(), or use sizeof()-1 to lose the NUL
Transmit function also blocks.
2019-12-25 09:56 AM
Use strlen() rather than sizeof(), or use sizeof()-1 to lose the NUL
Transmit function also blocks.
2019-12-25 10:13 AM
Thank you so much. It works.