Migration of SPI based application from Wemos D1 mini to ESP32-C3 mini

I have some code that I have used for several years on Wemos D1 Mini hardware which drives some HV5622 shift registers via SPI. I want to migrate this to us ESP32-C3 mini which is (I believe) designed as a plug in replacement. I have most things running (I was using an ESP32-S2 mini for testing) then I moved to ESP32-C3 mini hardware (Lolin).
My code compiles OK but will not run - continual resets:

ESP-ROM:esp32c3-api1-20210207
Build:Feb 7 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
Saved PC:0x40380080
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd5810,len:0x438
load:0x403cc710,len:0x918
load:0x403ce710,len:0x25f4
entry 0x403cc710

And I suspect the SPI setup has something to do with it. The code is set to use the ‘default’ spi pin assignments for the Wemos D1 mini - so I suspect that these need to be re-mapped to work on the ESP32-C3 mini though the more I research SPI on the C3 - the more confused I get.

My code looks like this:

SPI.begin();
SPI.setFrequency(100000);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1);

Might anyone be able to point me in the right direction?

  • Richard

Hi there,
Yea, That C3 is slightly different than the other variants when it come to SPI
You just need to define the pins for the SPI,
ie. SPIClass SPI_1(CS, D9, D8, D10);
HTH
GL :slight_smile: PJ
:v:

Hello and thank you for that - am I simply adding that in front of my existing SPI initialisation statements?

ie.

SPIClass SPI_1(CS, D9, D8, D10);
SPI.begin();
SPI.setFrequency(100000);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1);

OK, I tried that and I can see that I need to define CS and the other parameters - I shall have to go and read up more on those - will I be able to use the same physical pins as on a wemos D1 mini (esp8266) ? or am I in to a board change?

  • Richard

Hi there,
Not sure about the D1, those are for a XiaoC3 from the Xiao Grove Expansion thread.
check that out.
HTH
GL :wink: PJ

You’re close , you’ll get it going. :v:

Been away a few days - back at the desk and keen to pick this up.
I am just trying to understand how the SPI on the C3 mini is referenced as a I see that there are several SPI’s available - one of which is for internal use only.

I can see that using the SPIClass SPI_1(CS, D9, D8, D10); will allow me to control which pins are assigned, I do not yet understand the choice of the SPI_1 as I understand that SPI_2 is also an option.
Do I need to change all my references from SPI to SPI_1 to suit?
eg.
SPI_1.begin();
SPI_1.setFrequency(100000);
SPI_1.setBitOrder(MSBFIRST);
SPI_1.setDataMode(SPI_MODE1);
I have ‘tried’ many things but all seem to break at compilation stage.
I will try moving to some smaller code for testing the SPI setup.
Also, bottom line, am I actually going to be able to use the Lolin ESP32-C3 mini to drop in place of a Wemos D1 mini where I use D5, D6 and D7 (on the D1) positions for the connection to the peripherals as I do now?
If this is not going to be possible then it would be easier (for me!) to move to the ESP32-S2 and make a new board. I know it might seem as an extreme measure but at 62 years old - my abilities to grasp new concepts and ideas is very slightly diminished as compared to what it was 20, 30 or 40 years ago and whilst I might be better off knowing how to fish - the number of days that I have left to fish is similarly diminished and sometimes - just a box of fish might be all that I need - sad I know - but true.

  • Richard