I need to send conductivity data via UART RS485 to external device. My external device have its own communication frame via RS485 so I modified the code to read the frame that is comming to CN0359 EC device and send the answer with conductivity data back.
Read function works perfectly but when I want to send data, on serial monitor I see that data is corrupted (lots of random ?|:&*^23##$). What is strange that in debug mode (via Jlink) the CN0359 EC meter send data perfectly without errors and I dont know why it happens. I have tried to block interrupts but without change. Source code below.source.zip
This is nice work modifying the CN0359 code to send conductivity data as response to a command through RS485.
I think the issue, however, is with the RS485 communications. The CN0359 uses the ADM3483 which doesn't have true fail-safe receiver inputs. The schematic though has a 10k ohm termination resistance.
Does your external device have pull-up and pull-down resistors in its RS485 lines? Without these pull-up and pull-down resistors, random data is received to the UART when the bus is in idle condition since the receiver output is undefined. Can you show me the RS485 connection diagram of your external device and the CN0359
Thanks for the replay. External device have 510ohm pull-up and pull-down resistors. I tested it and, unfortuneatly termination is not an issue.
The biggest mystery is why in debug mode (break point to printf() in uart) everything works and in run mode not.
Below I attached a code from external device (its arduino code)
Hi KoRba88, is the "serial monitor" that you're referring to above the Arduino serial monitor? That is, has the data from the CN0359 been received by your Arduino (on Serial3), then retransmitted out one of the other Serials (Serial, Serial1, or Serial2)?
Have you tried just connecting the CN0359 directly to a host computer using a USB-RS485 adapter (such as https://www.digikey.com/product-detail/en/ftdi-future-technology-devices-international-ltd/USB-COM485-PLUS1/768-1038-ND/2139300 )
and confirming that it responds to commands properly as described here:
I see where you're controlling your RS485 DE signal:
digitalWrite(DIR485, RS485_zapis); RS485.println(tekst); delay(4); digitalWrite(DIR485, RS485_odczyt);
And this might be part of the problem - you're sending data, then waiting 4ms to disable the transmitter (enable receiver). If the CN0359 responds within this 4ms, you won't get the response (or you could get a corrupted response, if the receiver is enabled mid-transmission from the CN0359.)
Another point - it looks like Arduino serial writes are blocking - so the 4ms delay will not occur until your entire tekst is sent.
Try doing digitalWrite(DIR485, RS485_odczyt); right after the println.
You could also experiment with timing by using a much simpler Arduino sketch to pass raw responses from the CN0359 to the terminal. We recently modified the Arduino serial passthrough example to work with an RS485 half-duplex transciever:
Of course you'll have to modify baud rates, serial port numbers, and DE signals to match your hardware.
This should in theory act as a simple USB-RS485 adapter.
Hi Mark, the delay was an issue. Now its working. Thanks