2024-10-18 03:43 AM - last edited on 2024-10-18 04:32 AM by SofLit
I’m interfacing a JXBS-3001-RS Soil Sensor with an STM32L0 board using an RS485 transceiver with automatic direction control. While I can successfully send the request command to the sensor, I’m facing an issue receiving the sensor’s data.
I’m using Serial.Available() to determine when data is available from the sensor, but the condition for data availability is never true, so I cannot read any data. Code block is shown below:
startTime = milis();
while (milis() - startTime <= 500) {
if (Serial.Available() > 0) {
if (byteCount < sizeof(values_temp)) {
values_temp[byteCount++] = Serial.Read();
}
}
}
Additionally, I’ve verified the sensor’s output using a TTL-to-USB adapter and a logic analyzer, and I can see that the sensor is sending the correct data. However, the STM32L0 is still not detecting this incoming data.
To troubleshoot, I tested the same approach on a Raspberry Pi Pico, using the same RS485 transceiver and sensor. With the Pico, Serial.Available() behaves as expected, and it detects incoming data from the sensor correctly.
Given that the same setup works on a Raspberry Pi Pico but not on the STM32L0, what could be causing the STM32 UART to miss the incoming data? I’d appreciate any suggestions for correctly configuring UART to receive RS485 data on the STM32L0.
2024-10-18 10:47 AM - edited 2024-10-18 10:47 AM
What is this Serial.Available? Some Arduino-like C++ library for STM32? STM32duino?
> Verified that data is being sent by the sensor using a logic analyzer and a TTL adapter.
On STM32L0?
2024-10-18 11:15 AM
>>.. what could be causing the STM32 UART to miss the incoming data?
Signs would point to your board level driver implementation in Arduino, likely not being aware of the half-duplex operation, or the TX reflecting back into the RX, or how to manage the RX vs TX cases.
Review the board's variant code.. debug that.
2024-10-20 08:22 AM
Actually, I’ve implemented my own SerialAvailable() function for handling UART reception with a circular buffer. Here’s the function I’m using:
int SerialAvailable() {
return (RX_BUFFER_SIZE_1 + rx_buffer_head1 - rx_buffer_tail1) % RX_BUFFER_SIZE_1;
}
This function calculates the number of bytes available in the receive buffer by comparing the head and tail indices. I’m using a circular buffer for UART reception, and this function helps me determine how much data is currently available to read.
Even with this implementation, I’m facing the issue where no data seems to be received by the STM32L0. However, as I mentioned earlier, the sensor data is verified via a TTL-to-USB adapter and logic analyzer.
2024-10-20 08:30 AM - edited 2024-10-20 08:30 AM
If receive ceases for no clear reason - check for TX overrun condition & reset it.
2024-10-20 11:47 PM
Thank you for your suggestion regarding the TX overrun condition. I would like to clarify that when I encounter a TX overrun error, how can I reset it?
Additionally, I noticed that when I transmit the command to the RS485 sensor, instead of receiving the expected sensor data, I receive the command back. What could be causing this issue, and how can I ensure the sensor responds correctly?
2024-10-21 12:00 AM
I want to clarify that I am not using an Arduino-level driver. Instead, I have implemented a custom driver for the STM32 with a circular buffer for serial communication.
I am currently using auto direction control to manage the transmit and receive modes for my RS485 communication. Given the issues I'm experiencing with receiving sensor data, do I need to implement manual direction control instead? Would manually setting the direction enhance the reliability of communication in my setup?
2024-10-28 05:19 AM
@shibani wrote:I’ve verified the sensor’s output using a TTL-to-USB adapter and a logic analyzer, and I can see that the sensor is sending the correct data. However, the STM32L0 is still not detecting this incoming data.
So have you confirmed that the data is actually reaching the STM32L0's UART receive pin?