The UART interface is designed to send text or hex commands between an external device (e.g., Arduino) and a host. The maximum command or data block size is 127 bytes. Every command line may terminate with a special configurable byte (Packet end): CR (0x0D), LF (0x0A), 0x03 (ETX), or any user-defined value in the Byte field. The firmware also adds the ending signature to each of the commands that the device receives from a host and outputs to UART. If the end signature is not defined, the firmware waits 300 ms and outputs the whole buffer to a host.

The firmware supports only one UART interface, even if a chip has more UART interfaces.

Communication parameters

Baud rate: you can select it in the configuration
Data bits: 8
Parity: None
Stop bits: 1

CC2530

UART uses fixed pin:
P02 – RX (receive).
P03 – TX (transmit).
All pins have the TTL level 3.3V.

You should enable UART on P02 on an output pin in the configuration. Pin P03 is optional.

UART configuration for CC2530. P02 is required. P03 is optional
UART configuration for CC2530. P02 is required. P03 is optional.

CC2652

This chip allows using UART on any unused pin. All pins have the TTL level 3.3V.

  • You should define the RX pin first.
  • If you define only one pin in the configuration, the firmware supposes that it is the RX pin, and the firmware calculates the TX pin number automatically as TX = RX + 1
  • If you define two UART pins, you can use any pin number, but the RX pin is always first.

The figure below shows an example with RX and TX pins: P12 – RX, P14 – TX.

UART configuration for CC2652
UART configuration for CC2652.

FYI: TI LaunchPad™ kit with CC2652R uses P02 and P03 for RX and TX accordingly for XDS110 User UART.

Zigbee clusters

Zigbee cluster: ZCL_CLUSTER_ID_GEN_MULTISTATE_VALUE_BASIC
Zigbee attributes: ATTRID_IOV_BASIC_STATE_TEXT - UART data. You should use the "ZCL_DATATYPE_OCTET_STR" (0x41) or "ZCL_DATATYPE_CHAR_STR" (0x42) data types for this attribute.

Zigbee2MQTT commands

write – sends data to a UART.

Topic: zigbee2mqtt/[friedly_name]/set/action
Payload: text command

The following command allows you to send any bytes. The first byte in the array (2) is the number of bytes following the length.

Topic: zigbee2mqtt/[friedly_name]/set
Payload: {"action": [2, 0, 0]}

Example

if you want to send the following sequence of bytes: 0xAA 0x03 0x08 0x10 0x04 0xC9.

  1. Convert all bytes to decimal: 170 3 8 16 4 201.
  2. Count your bytes: 6.
  3. Make a payload string: {“action”: [6, 170, 3, 8, 16, 4, 201]}
  4. Send it using MQTT Explorer or a similar utility:
    1. Select the device in the tree (fig. 1).
    2. Go to “Publish” and specify the full topic name.
    3. Specify the payload.
    4. Click the Publish button.
Sending data to UART
Sending data to UART

The figure below shows data received from CC2530 on a Windows-based computer using Advanced Serial Port Monitor. Moreover, you can send data back using this terminal program by typing the necessary bytes in the edit box: AA#03#08#10#04#C9. Here, you do not need to count bytes and add the number in the front.

Incoming data in Serial Port Monitor
Incoming data in Serial Port Monitor

Comments
Harvey Specter
Posted at 01:38 June 3, 2023
Nirm
Reply
Author

Is it possible to bind the UART data transmission from end device to end device directly?

    Harvey Specter
    Posted at 05:41 June 3, 2023
    Owner
    Reply
    Author

    No, it is impossible.

Harvey Specter
Posted at 02:31 May 17, 2023
Patrick
Reply
Author

Can PTVO be used for transparent serial transmission between 2 hosts?
My usage example is sending UART commands from HomeAssistant with a CC2652P (Sonoff dongle) to a CC2530 with an mp3 module attached (connected via P02 and P03 to relevant RX/TX pins of the mp3 module) which can be controlled via UART commands.

    Harvey Specter
    Posted at 03:24 May 17, 2023
    Owner
    Reply
    Author

    Hi Patrick. I cannot say that it is fully transparent because it has the following limitations: strict communication parameters, bandwidth, data packet size, complexity of preparing command on the HA side.

    So, if you like to send a short fixed command once per minute, it will work. Otherwise, you should try it in your application.

Harvey Specter
Posted at 22:12 January 26, 2023
Lazabba
Reply
Author

Thank you for sharing your work and such a generic design!
One of the hobby use-cases I implemented with ptvo is a Victron uart consumer with a zha quirk stitching, parsing and converting messages. I worked around the 127 bytes length limitation, but would it be possible to make the uart message length configurable (I think zigbee makes it possible to fragment messages, but I might be wrong and/or missing the details)?

Harvey Specter
Posted at 22:05 November 23, 2022
Tom
Reply
Author

Hi there, thank you for this awesome firmware.

I had been looking for a while for something to write custom zigbee devices with and was surprised to find you had done the work already.

I was trying, without success to get UART communication to work with a CC2530.

I kept getting “zigbee_publish_error” from zigbee2mqtt, regardless of where the message was sent from (even occured trying to set ‘action’ via the webui)

I found in one of the other feature comment sections that it might not work on OUTPUT1.

Changing UART to OUTPUT2 fixed my problem.

Not sure if this is specific to my boards (cheap Aliexpress), but hopefully this helps anyone else

Harvey Specter
Posted at 05:06 April 14, 2022
JohnRob
Reply
Author

I’m setting a CC2530 to use in the UART mode. I may be dense but I can’t figure out what the last parameter is “byte 239” where the 239 can be changed.

Thank you
John

    Harvey Specter
    Posted at 09:25 April 14, 2022
    Owner
    Reply
    Author

    It is a custom (user-defined) values for “Packet end”.

Harvey Specter
Posted at 20:21 March 25, 2022
mantielero
Reply
Author

Newbie speaking here. I have created a firmware with Output P0.2 UART 9600, Input P0.3 UART 9600. I connected VCC, GND, P0.2 and P0.3 to USB-FTDI and also P2.0 to GND. Then I use putty under Linux and connected to the /dev/ttyUSB0 interface using 9600. But nothing appears on the screen. What else should I bear in mind?

    Harvey Specter
    Posted at 03:42 March 28, 2022
    Owner
    Reply
    Author

    1. P03 and P20 are not necessary. 2. Did you send a command from MQTT or vice versa as described on this page?

Harvey Specter
Posted at 19:37 January 22, 2022
Harrow
Reply
Author

Hello, first of all thanks for your work.
I need to connect a CC2530 to a UART of a device configured in this mode : (speed : 9600, data : 7 bits, parity : even, end byte 0x03).
I tried to configure your firmware but it seems data settings is set to 8 bits. There is a way to change this option and the that of parity ?
Thanks

    Harvey Specter
    Posted at 12:24 January 23, 2022
    Owner
    Reply
    Author

    Sorry, but the firmware cannot use these communication parameters.

Harvey Specter
Posted at 10:56 January 15, 2022
Serg
Reply
Author

It seems I can only send at most 127 bytes. If I try to send more, nothing is sent out to UART. Is there any way to overcome this limitation?

    Harvey Specter
    Posted at 06:22 January 16, 2022
    Owner
    Reply
    Author

    You can send data in chunks but let the firmware send a previous chunk before.

Harvey Specter
Posted at 23:00 November 21, 2021
gio
Reply
Author

Hi, i’m using uart functions on cc2530 in both directions. It works fine but i have a question: it would be possible to arrange an external z2m converter in a way that permit to read a uart code as tag in Homeassistant? I mean using the MQTT Tag scanner integration: https://www.home-assistant.io/integrations/tag.mqtt/

    Harvey Specter
    Posted at 03:49 November 22, 2021
    Owner
    Reply
    Author

    It is possible if you will create a converter yourself. You should copy and edit

    1
    ptvo_switch_uart: { ... }

    from Z2M\node_modules\zigbee-herdsman-converters\converters\fromZigbee.js to your custom converter.

      Harvey Specter
      Posted at 12:14 June 24, 2022
      gio
      Reply
      Author

      Sorry, could you show an example of converter to read uart code as tag, based on this guide?
      I don’t have enough skills to edit it.
      https://www.home-assistant.io/integrations/tag.mqtt/

      Harvey Specter
      Posted at 12:27 June 24, 2022
      gio
      Reply
      Author

      It would be great if you could add an option in the function to generate custom converter ,that automatically generate the converter for homeassistant tags.

        Harvey Specter
        Posted at 04:00 June 25, 2022
        Owner
        Reply
        Author

        Unfortunately, I don’t use HA and don’t know how this converter looks like.

Harvey Specter
Posted at 20:52 July 8, 2021
Karl
Reply
Author

Using SoftwareSerial library to print string to the cc2530 with a Arduino pro mini. Message received in Node-Red and MQTT Explorer 🙂 Arduino –> MQTT Broker works fine.

Can I send from MQTT Explorer or Node-Red and then receive string in Arduino? I have been trying to publish to the UART ….. no luck. Below is my Arduino code. Any pointers

#include

#define rxPin 13
#define txPin 12
#define ledPin LED_BUILTIN

// set up a new serial port
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
byte pinState = 0;

void setup() {
Serial.begin(9600);
// define pin modes for tx, rx, led pins:
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(ledPin, OUTPUT);

// set the data rate for the SoftwareSerial port
mySerial.begin(115200);

// test TX MQTT Explorer
mySerial.println(“From Arduino”);
delay(5000);
mySerial.println(“Arduino Second Try”);

Serial.println(“Test RX from MQTT Explorer”);
}

void loop() {
// listen for new serial coming in:

if (mySerial.isListening()) {
//Serial.println(“MySerial is listening!”);
}

if (mySerial.overflow()) {
Serial.println(“SoftwareSerial overflow!”);
}

if (mySerial.available()) {
Serial.write(mySerial.read());
}
}

    Harvey Specter
    Posted at 04:37 July 9, 2021
    Owner
    Reply
    Author

    Yes, you can send data in both directions. The page contains an example of how to do it using MQTT explorer.

      Harvey Specter
      Posted at 05:32 July 9, 2021
      Karl
      Reply
      Author

      Thx for confirming. Think I will prepare another flash file with inputs and outputs as normal switches. My setup only has the UART and the flashing LED. Device dos not show up like others in MQTT explorer. I had to write to l1 ON/OF before it showed up nicely.

      I have tried all your examples before I wrote this. Will provide feedback once I have created a new flash version.

Harvey Specter
Posted at 10:33 June 9, 2021
Parats
Reply
Author

Hello, I need to get some ascii datas form uart communication.
Could I set up a uart input ?

    Harvey Specter
    Posted at 03:29 June 10, 2021
    Owner
    Reply
    Author

    If you define UART on “Output”, it can send data in both directions. But you can configure communication parameters.

Harvey Specter
Posted at 18:38 May 20, 2021
Simon
Reply
Author

Hi, I’m using in uart mode and I’m getting an empty action after every action I expect, is this normal? I’m also getting 3 status messages directly after each other, is there a way I can limit this to 1?

    Harvey Specter
    Posted at 03:27 May 21, 2021
    Owner
    Reply
    Author

    Hi. The problem is not clear. Please, open an issue on github and attach screenshots with your settings, logs, etc.

Harvey Specter
Posted at 14:24 May 13, 2021
Peter
Reply
Author

Hi, I created UART communication between CC2530 and Arduino nano. It communicates via json. Here is an example what I send and receive:
sending data:
topic: zigbee2mqtt//set/action
payload: {’tilt_corr2′:20}

receiving data:
topic: zigbee2mqtt//action
payload: {“pos1″:0,”pos2″:0,”pos3″:0,”speed”:700,”op_pos1″:0,”op_pos2″:0,”op_pos3″:0,”tilt_corr1″:0,”tilt_corr2″:20,”tilt_corr3″:0}

It works well about 80% of time. But sometimes instead of json string I get just a bunch of numbers:
topic: zigbee2mqtt//action
payload: 10,123,34,112,111,115,49,34,58,48,44,34,112,111,115,50,34,58,48,44,34,112,111,115,51,34,58,48,44,34,115,112,101,101,100,34,58,55,48,48,44,34,111,112,95,112,111,115,49,34,58,48,44,34,111,112,95,112,111,115,50,34,58,48,44,34,111,112,95,112,111,115,51,34,58,48,44,34,116,105,108,116,95,99,111,114,114,49,34,58,48,44,34,116,105,108,116,95,99,111,114,114,50,34,58,50,48,44,34,116,105,108,116,95,99,111,114,114,51,34,58,48,125

Do you have any idea what could be the issue ?

    Harvey Specter
    Posted at 03:34 May 14, 2021
    Owner
    Reply
    Author

    Hi! This data packet contains a non-printable character (10). The converter cannot encode it to string.

      Harvey Specter
      Posted at 21:51 May 15, 2021
      Peter
      Reply
      Author

      Thanks for the answer. I’ve played with the line ending settings to be specifically the same and it started to work fine. Now I just need to figure out why is a random character in string missing sometimes, especially with high traffic. But it looks like Arduino -> CC5230 issue..

    Harvey Specter
    Posted at 18:14 January 5, 2023
    Esa
    Reply
    Author

    Hi Peter

    Any chance of getting your insights or even source code how you communicate through the UART via the JSON?

    I got stm32 Blue Pill to send data through the UART but I’m stuck on how to actually use it.

    Kind regards

Harvey Specter
Posted at 19:41 April 11, 2021
Pavel
Reply
Author

Somehow I am not getting anywhere.
I am trying to use CC2035 with a 4 relay.
The relays switch with:
turn_on_action:
– uart.write: [0xA0, 0x01, 0x01, 0xA2]
turn_off_action:
– uart.write: [0xA0, 0x01, 0x00, 0xA1]

i can’t figure out how to set these commands with mqtt.

Output1 -> P02 -> UART
Output2 -> P03 -> UART

    Harvey Specter
    Posted at 03:57 April 12, 2021
    Owner
    Reply
    Author

    Hi Pavel. Where do you execute the “uart.write” command?

    Please, look here, how to send data using zigbee2mqtt
    https://ptvo.info/zigbee-configurable-firmware-features/uart/

    You should select “Packet end: none” in the UART settings in your case.

      Harvey Specter
      Posted at 13:14 April 12, 2021
      Pavel
      Reply
      Author

      This one example was from ESPHOME, and it worked fine. I want to replase esp01 with cc2530 like here: https://modkam.ru/?p=1551
      After flashing it was integrated into z2m and over mqtt I try to send this commands like:
      [0xA0, 0x01, 0x01, 0xA2]
      [0xA0, 0x01, 0x00, 0xA1]

        Harvey Specter
        Posted at 13:28 April 12, 2021
        Owner
        Reply
        Author

        I’ve sent you a link where you can see the corresponding example. In your case, a payload will look like this:

        1
        2
        {“action”: [4, 160, 1, 1, 162]}
        {“action”: [4, 160, 1, 0, 161]}
          Harvey Specter
          Posted at 13:34 April 12, 2021
          Pavel
          Author

          ok, I have to convert hex code into the number. This was the point. Thank you!

Harvey Specter
Posted at 11:54 April 9, 2021
Roland
Reply
Author

Thanks, did some testing but now I can’t get any UART data out, could be I’m making an error somewhere. I’m using a CC2531 USB dongle, this is the config:
/====
Board type: CC2530 (without external oscillator, like ??2531 dongle or Sonoff BasicZBR3)
Device type: Router
Transmit enable (TXEN): P12Receive enable (RXEN): P14
Update firmware’s timestamp : 2021-04-09
Status LED: P11, Periodic (every 5 seconds)
Set default reporting interval (s): 10

Output pins:
P00: Output 2, GPIO, External pull-up
P02: Output 5, UART (Baud rate: 9600, Packet end: 0x0D)

Input pins:
P12: Input 1, GPIO, External pull-up
====/
I do see that’s it is using TXEN and RXEN but there is no RF amp on the board and I can’t configure this in the main control panel when CC2531 is selected.
The board does pair ok, the LED works, only the UART does not.
Do I need a custom converter for the UART functions?

    Harvey Specter
    Posted at 12:27 April 9, 2021
    Owner
    Reply
    Author
      Harvey Specter
      Posted at 14:35 April 9, 2021
      Roland
      Reply
      Author

      I have a logic analyzer and connect that to P0.3 on the header. That’s where I’m expecting the serial data. I have found that P0.3 is TX and P.02 is RX. Did not do any testing with RX yet. Would like to use that as well in the future. USB is only for power in this configuration. I find the USB dongle a nice board because it has the leds and voltage regulator already on it. I use node red to send and recieve data to the board.

        Harvey Specter
        Posted at 08:36 April 10, 2021
        Owner
        Reply
        Author

        How do you test TX data? If you use Z2M in the middle, you should have a log file there. Maybe, it contains some messages or errors related to your device.

Harvey Specter
Posted at 17:47 April 6, 2021
Roland
Reply
Author

Done some testing with the UART, I got sending a string to work using the topic “zigbee2mqtt//l2/set/action”. Your example command does not contain the output number. If I leave this out I get a publish error. The second example (sending bytes) does not work. Can you give a more detailed example. What should I inject in the node? I did try a string, a JSON line but nothing works.
Thanks!

    Harvey Specter
    Posted at 03:49 April 7, 2021
    Owner
    Reply
    Author

    Did you try a firmware released 2021-04-05? I’ve fixed this problem there. Or you may configure UART on Output 1.

    Harvey Specter
    Posted at 14:12 April 10, 2021
    Roland
    Reply
    Author

    Started with a clean configuration with only the status led on P11 and UART P02 on output 1, and now I have some serial data on pin P03. I think I had a false combination of inputs/outputs that prevented the UART from working. To get the RX portion working do I need to configure P03?
    I bought you a coffee as a thank you for your support.

      Harvey Specter
      Posted at 06:02 April 11, 2021
      Owner
      Reply
      Author

      The old version of the firmware supported UART on Output 1 only. You need to configure only one pin, P02 or P03. The latest version supports UART on any output. Thank you for the coffee :).

Leave a Reply to Parats
Cancel Reply