Manage cookies

We use cookies to improve our services. Read more about how we use cookies and how you can refuse them.

The necessary cookies help to make the website work properly.

Anonymous statistical cookies help to understand how visitors use the website.

  • Home Automation, Raspberry Pi
    3 min | 68045

    #Zigbee: Flashing a CC2531 dongle using a Raspberry Pi

    Home Automation, Raspberry Pi | 3 min | 68045


    Last April, I published a tutorial about connecting the Aqara sensors to a Raspberry Pi without using the Xiaomi Gateway. To make that possible, I needed a CC Debugger to flash the TI CC2531 Zigbee Dongle. This debugger was used only one time, and then the Zigbee-USB dongle worked without any problem.

    In this article, I will cover a way to flash the CC2531 without the CC Debugger. This reduces project costs (about $10 for debugger + cable adapters) and waiting time. Usually, you wait 30 days to get a low cost version of the debugger (using the cheapest shipping option). Let's start!

    Hardware

    You need the following hardware for this project:

    DIY: Hardware Connection

    You need a soldering iron and 4 jumper cables. Then, solder 4 wires to the pins: GND, DC, DD and RST of the CC2531 header (see CC2531 Pin Header in Fig. 1a). The header is very small and you can bend the pins a little, if you cannot solder them directly.

    However, if you are not good at soldering, or if you don't have any soldering iron, you can buy the following adapter:

    Raspberry Pi
    • CC2531 Sniffer Adapter

    The adapter connects using a flat cable to the CC2531 and it has a bigger pin header on board side. Thus, you can connect the female jumper connectors directly to that header (see CC Debugger Pin Header in Fig. 1a). It doesn't matter which option you have chosen (solder or adapter), but then, connect the other end of the wires to the Raspberry Pi header (see Fig. 1b) as described in the following table:

    Raspberry PiCC2531
    GNDGND
    Pin 38DD
    Pin 36DC
    Pin 35RST

    After connecting the CC2531 header to the Raspberry Pi headers, plug the USB dongle to a USB port of the Raspberry Pi and then, power up the Raspberry Pi.

    If you use the flexible flat cable (FFC) provided with the adapter and you want to connect male jumper connectors from there to the Raspberry Pi, please be aware that connection is not described in Fig. 1a (CC Debugger Pin Header). You need to mirror it.
    CC2531 PINsRaspberry Pi
    Fig. 1a: PIN description CC2531Fig. 1b: PIN description Raspberry Pi

    DIY: Flashing the CC2531

    1. On the Raspberry Pi, check if you have already installed Wiring Pi typing: gpio -v in the terminal. If not, install it following these instructions.
    2. Clone the jmichault/flash_cc2531 repository typing the following:
      git clone https://github.com/jmichault/flash_cc2531.git
    3. Go inside the flash_cc2531 folder and check if the Zigbee-USB dongle is wired correctly and if it's identified:
      cd flash_cc2531
      ./cc_chipid
    4. You should see ID=b524. If you get any other text (e.g. 0000 or ffff), re-check your wiring.
    5. Download the latest firmware from Koenkk/Z-Stack-firmware.
      wget https://github.com/Koenkk/Z-Stack-firmware/archive/master.zip
      unzip master.zip
      # (**)
      cd Z-Stack-firmware-master/coordinator/Z-Stack_Home_1.2/bin/default/
      # (*)
      unzip CC2531_DEFAULT_<<yyyymmdd>>.zip   
    6. Erase the CC2531 flash with ./cc_erase
    7. Flash the firmware using ./cc_write /path/to/CC2531ZNP-Prod.hex. This will take about 3 min.
    8. Disconnect the wires/adapter and reboot the Raspberry Pi
    (*) Note 1: change yyyymmdd with the actual date of the file (check it here: /bin/default, /bin/source_routing).

    (**) Note 2: I used the default version of the Z-Stack coordinator. But:
    • a. If you have a network of 1 - 30 devices, the Z-Stack_Home_1.2 /bin/default firmware is recommended.
    • b. If you have a network of 30+ devices, the Z-Stack_Home_1.2 /bin/source_routing firmware is recommended.
    This changes the folder and file in step 5. More info available here.
    Raspberry Pi 1 users
    I copy here a comment written by whooty on 01.26.2020 (THANKS!):

    Just did it with a pi 1. all you have to do is use different pins. Check the documentation for flash_cc2531, there is a section which tells you how to change the pins you use. Use 'gpio readall' to figure out which pins you have connected to what, and use the wPi number off that for the command flags in flash_cc2531.

    Conclusions

    This tutorial covers an alternative way to flash the CC2531 without using the official TI CC Debugger or the low cost SmartRF04EB. If you followed the steps as described, you should have your CC2531 dongle flashed with the firmware. Then, you can follow this article to integrate the Aqara sensors to Hass.io: #Raspberry Pi: Xiaomi Sensors & Home Assistant (Hass.io) or use a broker explained here: #Zigbee: Xiaomi Sensors using Raspberry Pi (without Gateway!).

    Acknowledgements

    Many thanks to the developers of the following software:


    Comments

    Balla Tibor 11.04.2019

    I bought the CC2531 sniffer from the banggood link you provided, but it can be programmed only with CC Debugger. Not all chinese CC2531 sniffers can be programmed with Raspberry Pi, the flash_cc2531 ./cc_chipid always return FFFF!

    Simon 01.17.2020

    I really like this approach and my only question is whether I can make this work with a Raspberry Pi 1. Any hints?

    VPY 05.20.2020

    Hello Any idea why write stop for that write 1/128? I'm using cc2530 so chipid different.

    /flash_cc2531# ./cc_erase
      ID = a524.
      erase result = 00a2.
    /flash_cc2531# ./cc_write CC2530ZNP-Prod.hex
      ID = a524.
      reading line 15490.
      file loaded (15497 lines read).
    writing page   1/128.

    Bob Landolfi 09.07.2020

    Thanks so much for this very helpful resource! I came for the pinouts, your diagrams and instructions were by far the best I found. One little thing: The second shell command should be "unzip master.zip"