Close
0%
0%

More WeAct CH5xx

Follow on to my WeAct CH573, CH582, CH592 RISC-V modules. UART, Timer, SPI for NEOpixels.

Public Chat
Similar projects worth following
260 views
As promised in my original Getting stared with the WeAct CH5xx project I have returned with a deeper dive into this family of tiny, low cost RISC-V modules.

For starters I want to set the stage again.  My development environment is based on the MounRiver Studios IDE running on a Linux Mint PC.  As I detailed in the previous hack on this subject I created some bash scripts to make things easier.  In this project I have updated MounRiver to version 1.80. I also came across some anomalies in the Example programs given on the WCH github. For an unknown reason the individual examples given tend to exclude some references to the libraries for other peripherals.  This can easily be solved by editing the .cproject file....  more on this later.

My aim here is to take a deeper dive into several peripherals covering more advanced concepts such as interrupts, as well as fixing some of the oversights in the github examples.  The idea is to go beyond "Blinky", but we will be blinking the LED - as well as running a NEOpixel strip.

Getting a project up and going in Moun River

- this can be a challenge under Linux - there is no simple way to associate the IDE program with a ".wvproj" file.  Anyway, even if we could, we would still have to do some manual intervention to get our project to be totally usable.  So here is the procedure that I use:

  • I like to create a separate directory with a "git clone" of the entire ch5xx repository to keep as reference.
  • create a separate directory to use as a Moun River workspace.
  • Open Moun River using the directory just created as workspace.
  • select the "Create a new MounRiver Project" option, selecting the CH592F board.
  • Exit Moun River.
  • Add my files from the Files section into the CH592F/User directory in the workspace, overwriting existing files where necessary.
  • You will then need to edit the "CH592F/.cproject" file to liberate all of the peripheral drivers.

Although I developed this project on a CH582 board I specified the CH592 above because there is no repo for the CH582 board, and the CH583 repo does not include samples for spi0. The 583 has 2 spi I/Fs but the 582 only has one.

At this point it is a good idea to close the IDE and edit the ".cproject" file from outside of the IDE.  It should be located in your_workspace/CH592F.  We will need to change the word "excluding" in line 263 where it says "<entry excluding="CH59x_adc.c|C..." to "including".  This will liberate the excluded drivers in the "StdPeriphDriver" directory so we can use them later.

Now we can re-start the IDE and get to work!

Pin Re-Mapping:

Most CH5xx development modules use the smaller 'F' series MCUs which have a constrained set of I/O pins brought out on the chip.  This may be exacerbated by board designs which may or not bring out all of the available pins.  For this reason I wanted to include examples of how to select alternate pins.  I found that I needed to do so after reviewing the I/O that I wanted to use for this project and closely examining the documentation for the MCU I am using.  My constraints were not to use PA8 which is where the on-board LED is connected on many boards as well as being able to use spi0 for the NEOpixels.  I also want to try to use a WCH-LinkE programmer on my own board designs.

Serial Example:

We begin with a serial example derived from the example automatically generated when we created the Moun River project.  The IDE is nice enough to provide us with some "stdio" functionality for the serial ports.  Although we see some examples using a PRINT() function, and other using a non-formatted function, printf() is available once the serial port is set up using the included driver.  I've been writing in 'C' for too long and can't live without printf. Most of the CH5xx chips offer up to 4 serial ports with an alternate pin layout available for each.  That said - the CH582F module that I used to develop this project left me with only 1 choice for the serial demo.  I ended up with UART0 on the default pins.  I wanted to include an example...

Read more »

Main.c

Main project

x-csrc - 6.96 kB - 10/18/2024 at 23:20

Download

NEO.h

defines for the NEOpixel routines.

x-chdr - 361.00 bytes - 10/18/2024 at 20:16

Download

UartPins.c

Routines to setup the UART(s).

x-csrc - 802.00 bytes - 10/18/2024 at 20:16

Download

Neo.c

NeoPixel routines.

x-csrc - 1.34 kB - 10/18/2024 at 20:16

Download

  • 1
    Connecting to NeoPixel Strip

    We need to note that the CH5xx MCUs are 3V3 systems.  NEOpixel strips typically require a 5V pulse stream on the Data Line.  So we need some type of level shifter on the SPI MOSI line. I prefer just using a regular old TTL Inverter like a 74LS04.  A 74HC14 works even better as it will clean up the signal.  In either case connect the MOSI output to pin 1 of the inverter. Connect pins 2 and 3 together. Connect a resistor (100-500 ohms) from pin 4 to the data line of the NEOpixel strip.

View all instructions

Enjoy this project?

Share

Discussions

Does this project spark your interest?

Become a member to follow this project and never miss any updates