I'm trying to send a single char ("A") to my STM32 from my ESP32. I can see that the char goes through as I am receiving the char back on the ESP32 in the Arduino serial monitor but I can't seem to understand how to access it for using it to do something else on the STM32. Here is what I've been trying...
//STM32 Code:
uint8_t RxTx_1[100];
while (1)
{
/* USER CODE END WHILE */
HAL_UART_Receive(&huart1, (uint8_t*)RxTx_1, sizeof(RxTx_1), 100); // Receive comms from ESP32
if (RxTx_1[0] = "A"){
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); // Blink
HAL_Delay(1000);
}
HAL_Delay(1000);
HAL_UART_Transmit(&huart1, (uint8_t*)RxTx_1, sizeof(RxTx_1), 100);
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
I know its got to be something simple but I can't seem to find anything online about how to do it.
CodePudding user response:
To expand on the comment from @πάντα ῥεῖ:
"A" is a string literal, with a type of const char[N]. This particular one is the string/array {'A', '\0'} (remember the terminating null-character). So if (RxTx_1[0] = "A") compares your Rx char to a pointer.
'A' is the character A with a char type, and if (RxTx_1[0] == 'A') does what you want.
