Close
0%
0%

CH583M - 3 NEOpixel Strips

Deep dive into the CH583 - DMA, alternate pins, interrupts.

Public Chat
Similar projects worth following
Driving 3 NEOpixel strips from a CH583M RISC-V MCU.

This is an update for Christmas - We attempt to make some twinkling Christmas lights with 3 NesoPixel strips on a CH583 microcontroller.

In this project we will take a deeper dive into the small but powerful CH583 RISC-V MCU. The under the hood dive will reveal how we use alternate pins and DMA to drive 3 NEOpixel strips. My original intent was to allow 4 strips but none of the CH5xx MCUs offers sufficient resources. The secret to achieving this small miracle is using alternate I/O pins for the SPI peripherals.  For example, even with the CH582F (or 592), we could drive 2 strips by connecting one to the MOSI pin and the other to the alternate MOSI_ pin on the single SPI.  We then proceed to alternately send one buffer of colour data to SPI0 and then change the pin assignment and send a different buffer to the same SPI0.  As a bonus we will look at using the CHIP ID register to appropriately configure the SPI at power-up.

 My grateful thanks to JLCPCB for making the process of designing and fabrication/assembly of my RISC-V boards so easy.

I have chosen to use the CH583M for this project because it has 2 SPI peripherals.  Unfortunately it does not offer alternate pins on SPI1 so we can only drive 3 strips total.  SPI1 also does not support DMA.

ChipID:

In this project we are using Serial Output on UART1 (Tx = A9). A Welcome message as well as possible status and error messages are displayed using printf(). Before we display the Welcome message we read the R8_CHIP_ID register into the ChipID variable which will be used to make setup decisions. This register contains the last 2 digits of the chip's part number in HEX (0x83) which we incorporate into the Welcome message..

SPI Setup:

The SPIsetup( ) routine in hardware.c sets up the SPIs, controlled by #define NUM_STRIPS in NEO.h as well as the #define DMA directive. Invalid configs may generate a compile error and/or a report via printf(). The numbering scheme we use has Strip0 using SPI0, then Strip1 using SPI0 with MOSI assigned to use it's alternate pin. We note that the naming convention for alternate pins has an underscore after the name, eg: MOSI0_.  Strip2 (if we are using a 583) uses SPI1. The other SPI pins are not used although you will see where I used SCS0 as trigger for the logic analyzer. It is not necessary for the operation of the NEOstrips.

We will be using the code examples provided here in the Files section.  Follow the Moun River setup given in my previous project and then add/replace these files into the src subdirectory. We will probably need to do a refresh at this point.

Simple usage:

To just light up a strip we don't need to get into the animations. All of the strips are automatically cleared by our software at boot time.  This is, of course, necessary because the strips act as memories and will remember the previously illuminated pixels.

To set a strip to one of the example colour arrays included at the top of Neo.c we can set up the strips structure as follows:

Strips[0].pixels = Strip;  //  will display the colours contained in the Strip array
Strips[0].len = 15;         //  here we assume the 1st strip has 15 pixels

The Show() function call will display each of the configured strips in turn.  The DelayUs call tells the strips that we are done loading pixel data. The mstTick++ and DelayMs routine is used to create animation timing. Show() is where we switch between standard and alternate pins. For example we switch to the alternate SPI0 pin set using the following command.

if( curStrip == 1 ) { R16_PIN_ALTERNATE |= RB_PIN_SPI0;  }      //  switch to alternate pins

if( curStrip == 0 ) { R16_PIN_ALTERNATE &= ~RB_PIN_SPI0; }  //  switch to standard pins

Show() also selects between 2 and 3 bit compression depending on the DMA setting.

There are several #defines in the NEO.h header...

Read more »

Main.c

added brightness control to Xmas animation - Dec. 19, 2024

x-csrc - 5.97 kB - 12/20/2024 at 00:13

Download

Neo.c

added brightness control to Xmas animation - Dec. 19, 2024

x-csrc - 10.32 kB - 12/20/2024 at 00:13

Download

hardware.c

added brightness control to Xmas animation - Dec. 19, 2024

x-csrc - 2.71 kB - 12/20/2024 at 00:12

Download

NEO.h

added brightness control to Xmas animation - Dec. 19, 2024

x-chdr - 1.62 kB - 12/20/2024 at 00:12

Download

  • 1 × CH583M Full dev Kit see Link in the left column

  • CH5xx 3 NeoPixel strips

    CanHobby.ca12/16/2024 at 11:31 0 comments

    Nov. 16, 2024 - Original submission.

    Dec. 16, 2024 - added the "Xmas" animation example.

    Dec. 19, 2024 - added Brightness control to the "Xmas" animation example.

View project log

Enjoy this project?

Share

Discussions

Does this project spark your interest?

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