2022-11-18 01:16 AM
Hi,
I am working on stm32f051c8t6tr microcontroller, from this I want to read some sensor data with UART1 and same data I want to transmit to another UART. Can you please suggest some example code related to my task. I am new to this controller.
I have tried one code also but its not working, I will share the code in below
HAL_UART_Receive(&huart1,(uint8_t *)buffer,10,10);
HAL_UART_Transmit(&huart2,(uint8_t *)buffer,10,10);
The above two line of code only I tried, buts its not giving any output; Please help me on this.
2022-11-19 11:02 PM
What sensor are you talking about? What makes the sensor send 10 bytes? You need to give us more information
2022-11-19 11:10 PM
Hi ,
Thanks for the reply.
Actually I am using Co2 Sensor, from that Co2 sensor I want to read the sensor data from one UART to another UART. The Co2 sensor is UART communication only. I am connecting Co2 sensor for one UART to receive the sensor data and same sensor data I want to transmit to another UART in stm32 controller. This is the task, can you please suggest some code to read exact data from sensor.
I have used the below code
HAL_UART_Receive(&huart2,(uint8_t *)BUFFER,sizeof(BUFFER),100);
if(HAL_UART_Transmit(&huart1,(uint8_t *)BUFFER,sizeof(BUFFER),100)!=HAL_OK);
But its showing 0 value.
2022-11-20 12:08 AM
You're posting the same question and not giving enough information. I've asked what kind of sensor and you saying its a Co2 sensor means nothing. A part number will tell us a whole lot more information.
2022-11-20 12:56 AM
hi,
please find the attachment of co2 sensor datasheet image.
2022-11-20 06:56 AM
HI
I AM WAITING FOR YOUR REPLY.
2022-11-20 08:14 AM
The reason your reading 0 is because you didn't send a command to read a register. Your HAL_UART_Receive(&huart2,(uint8_t *)BUFFER,sizeof(BUFFER),100) times out in 100ms. You also don't read the HAL return status so you didn't see it return HAL_TIMEOUT. So you may think the STM32 received 10 bytes but it didn't.
Then there are return values are in ASCII and they are not consistent in length so reading 10 bytes is not going to work. HAL_UART_Receive_IT(&huart2,(uint8_t *)BUFFER, 1) is going to work better for you. You need to fill your buffer one character at a time until until you receive a CR and LF.
You need to read the data sheet more thoroughly especially UART COMMAND PROTOCOL section.
2022-11-20 08:40 PM
Hi,
Can you please tell me how to implement to fill buffer character.
2022-11-20 10:58 PM
Enable interrupts for both USART ports in STM32 Cube configurator (put checkboxes on usart1/2/.. global interrupt/etc. on relevant tabs). HAL driver algorithms use interrupts.
2022-11-20 11:02 PM
Hi,
I have enabled both side interrupts, still now I am getting 0 values only.
2022-11-20 11:04 PM
Hi,
Please tell me how to send a command to read a register