2022-11-27 06:40 PM
I want to connect the sensor to the STM32 board and read the measured value with uart, but I can't get the sensor value
So I tested with HAL_OK to see if the uart communication works well, but it says it can be transmitted, but it's not receiving, so I don't know what to do
I need to check with usb to uart module, but I don't have it
How can I get reception?
bwt61 sensor datasheet : https://images-na.ssl-images-amazon.com/images/I/A1muNMR3otL.pdf
code
void bwtTask(void const * argument)
{
/* USER CODE BEGIN bwtTask */
uint8_t Tx_bwt_data1[3] = {0xFF, 0xAA, 0x52};
uint8_t Tx_bwt_data2[3] = {0xFF, 0xAA, 0x67};
uint8_t Tx_bwt_data3[3] = {0xFF, 0xAA, 0x60};
uint8_t Tx_bwt_data4[3] = {0xFF, 0xAA, 0x65};
uint8_t Tx_bwt_data5[3] = {0xFF, 0xAA, 0x66};
uint8_t bwt_data[33] = {0x00, };
/* Infinite loop */
HAL_UART_Transmit(&huart6, (uint8_t*)&Tx_bwt_data1, sizeof(Tx_bwt_data1), 0xFF);
HAL_UART_Transmit(&huart6, (uint8_t*)&Tx_bwt_data2, sizeof(Tx_bwt_data2), 0xFF);
HAL_UART_Transmit(&huart6, (uint8_t*)&Tx_bwt_data3, sizeof(Tx_bwt_data3), 0xFF);
HAL_UART_Transmit(&huart6, (uint8_t*)&Tx_bwt_data4, sizeof(Tx_bwt_data4), 0xFF);
HAL_UART_Transmit(&huart6, (uint8_t*)&Tx_bwt_data5, sizeof(Tx_bwt_data5), 0xFF);
for(;;)
{
osDelay(1000);
HAL_UART_Receive(&huart6, (uint8_t*)&bwt_data, 11, 0xFF);
for(int i = 0; i < 11; i++){
printf("%02X ", bwt_data[i]);
}
printf("\n\r");
}
/* USER CODE END bwtTask */
}
2022-11-27 07:42 PM
Use at least an interrupt on incoming asynchroneous uart bytes, and queue them in a sw fifo buffer which will be consumed by your printf. What if the printf or interrupt or other task hold your task longer than one incoming byte duration? Check out for overrun flags at least.