Generic AliExpress CH32V003 module SPI question - Page 1
Forum section: electronics / general

author: rka
author_rank: Newbie
timestamp: July 25, 2024, 12:22:41 am
content: Hello All.Moving on with my CH32VXXX explorations, I am now working with a generic AliExpress CH32V003 ($0.62/ea) PCB module ("SEIKO"?) to see whether I can get SPI working with it in order to use a LCD display with my design.Sadly, My trial here hasn't been very successful.I am using a simple core program that just displays to my PUTTY terminal (to ensure it is alive), I am trying to output a "hello world" to a simple el-cheapo 1602 LCD display using SPI, directly wired to the 1602. "Easy Peasy?"The program is compiled on Arduino using the WCH '.json' preference that uses the WCH -V003 board definitions.The CH32V003 Reference manual tells me that PC7 on the board is MISO, and PC6 is MOSI. As a result, I am wiring the LCD as follows:RS -> PC7, EN -> PC6, D4 -> PD0, D5 -> PD1, D6 -> PD2, D7 -> PD3The program compiles and uploads without a problem using the "LiquidCrystal.h" Arduino Library, but even though it compiles successfully, the actual codes execution hangs almost immediately when started.The 'hang' occurs when I define the LCD device, and when I comment out the LCD device's activation the PUTTY terminal thencomes alive, telling me that the hang-up is in the invocation of that bit of library code.I'm hoping someone with experience in SPI, or the CH32V003 sees this and can straighten me out here.As always, appreciate kind consideration and time.rka/** Program: LCD_Hello_24* LCD RS Pin --> MISO --> PC7* LCD EN Pin --> MOSI --> PC6** An attempt to use SPI to talk to the LCD display with* the inexpensive CH32V003 board.**/#include <LiquidCrystal.h>/** const int rs = 7;* const int en = 6;* const int d4 = 8;* onst int d5 = 9;* const int d6 = 10;* const int d7 = 11;*///Note: Defining 'lcd' causes program to hang - I have tried it using the// he labels (Below) or the 'pin' numbers. Neither workLiquidCrystal lcd( PC7, PC6, PD0, PD1, PD2, PD3 ); //Inform library of pinsvoid setup() {Serial.begin(115200);Serial.print("\n\r\n\rLets see what comes out\n");// pinMode(7, OUTPUT);// pinMode(6, OUTPUT);// pinMode(8, OUTPUT);// pinMode(9, OUTPUT);// pinMode(10, OUTPUT);// pinMode(11, OUTPUT);// Note: The 'device' lcd, once defined, just locks things up// lcd.begin(16, 2);// lcd.print("Hello World");}void loop() {Serial.print("\n\r Some Serial\n"); // when 'lcd' undefined, his displays// on the serial monitordelay(1000);// lcd.setCursor(0,1);// lcd.print(millis() / 1000 );}

author: Shonky
author_rank: Frequent Contributor
timestamp: July 25, 2024, 04:12:16 am
content: Your LCD is not SPI. You might be using CPU pins that can function as SPI, but that doesn't mean you're using SPI. The library is just bit banging presumably.Is R/W tied to ground? Presumably without driving R/W it's driving the LCD blind in which case it shouldn't be hanging. Just won't work if you have the wrong setup.Are you sure about the pin numbers for your Arduino?Exactly which CH32V003 are you using? Maybe post a picture or diagram of your wiring? Your pin numbers don't seem right from having a quick look around.

author: brucehoult
author_rank: Super Contributor
timestamp: July 25, 2024, 05:09:53 am
content: Quote from: Shonky on July 25, 2024, 04:12:16 amOnly the 20 pin package brings SPI SCLK out so either 1) the question doesn't need asking, or 2) OP has no paddle if the LCD actually used SPI.MISO / MOSI / SCLK are pins PC7 / PC6 / PC5 and can't be changed, so he's got that right, except I don't see them using clock. The 16 pin package has PC7 and PC6 but not PC5.You can use the SPI to create a UART-style bitstream without using SCLK (most easily 6N1). Is that how the LCD works?

author: Shonky
author_rank: Frequent Contributor
timestamp: July 25, 2024, 06:25:30 am
content: Quote from: brucehoult on July 25, 2024, 05:09:53 amGiven OP specifically mentions connecting RS, EN, D4-D7, this is likely a HD44780 style LCD. No UART, no SPI. The library being used is also for that type of interface.Given SPI is more likely not involved, the question still needs asking. SCLK wasn't mentioned so not sure how that points to a 20 pin version.

author: brucehoult
author_rank: Super Contributor
timestamp: July 25, 2024, 06:40:49 am
content: Quote from: Shonky on July 25, 2024, 06:25:30 amOh I see. That uses a 4 or 8 bit parallel interface. So why was SPI mentioned at all?It does still require a clock, but but yeah you can bit-bang that using an arbitrary set of GPIO pins. More efficiently if they're all in the same typically 8 bit port.And, yes, the Arduino pin numbers have to be mapped to device pin numbers.

author: Shonky
author_rank: Frequent Contributor
timestamp: July 25, 2024, 06:47:54 am
content: Quote from: brucehoult on July 25, 2024, 06:40:49 amHence my response? Read all 2 posts next time?The "Clock" here is EN(able) as mentioned in the original post. Supplied to the library that should then do the big banging as required.

author: rka
author_rank: Newbie
timestamp: July 25, 2024, 02:02:53 pm
content: All,The basic code I used was with a YouTube project that took an Arduino, and assured "The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver.... you can usually tell them by the 16-pin interface.In the given circuit:LCD RS pin to digital pin 12 (in my case, MISO - PC7)LCD Enable pin to digital pin 11 (in my case MOSI - PC6)LCD D4 - LCD D7 pins - to available PD0, PD1, PD2, PD3LCD R/W pin to groundLCD VSS pin to groundLCD VCC pin to 5v (supplied by LinkE programmer).The chip is the CH32v003F4P6, 20pin package, and here is a picture of the board

author: Sajeev
author_rank: Contributor
timestamp: August 03, 2024, 11:06:52 am
content: Dear,Try this assembly code. Tetsed and found ok.RegardsSajeev