PIC32MX Clicker2 with SPI Serial LCD Adapter

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
Terry.Stefanski
Posts: 23
Joined: 29 Jan 2016 21:13

PIC32MX Clicker2 with SPI Serial LCD Adapter

#1 Post by Terry.Stefanski » 16 Jul 2021 17:03

Greetings:

I have deployed a couple of custom test boxes using this combination on SPI2, but have run into a strange problem. I am working on a new application, using the exact same code as a previous project that works properly, but the 4 X 20 alphanumeric display will not initialize. If I upload and run the working program, the LCD works with my new program, as long as the LCD is not powered down. I can reset the CPU module, even issue a hardware reset to the LCD and it continues to work correctly.

Pertinent code:
program MAND_LCD
'
' Declarations section
'
include "clicker_2_PIC32MX"
'
' I/O Bit assignments
'
dim PRIN0 as sbit at PORTA.2 'Output
dim PRIN1 as sbit at PORTA.3 'Output
dim ADDATS as sbit at PORTA.6 'Output
dim LD2 as sbit at PORTA.10 'Out-Clicker2 on-board LED2 (for debug)
'
dim OSTR0 as sbit at PORTB.13 'Output
dim OSTR1 as sbit at PORTB.14 'Output
'
dim LD1 as sbit at PORTE.3 'Out-Clicker2 on-board LED1 (for debug)
dim T1 as sbit at PORTE.4 'In-Clicker2 on board button 1 (for debug)
'
' Port Expander module connections for SPI LCD interface
' SCK (RG6), MISO (RG7) & MOSI (RG8) defined in driver
'
dim SPExpanderRST as sbit at LATA4_bit
dim SPExpanderCS as sbit at LATE6_bit
dim SPExpanderRST_Direction as sbit at TRISA4_bit
dim SPExpanderCS_Direction as sbit at TRISE6_bit
'
'******************************************************************************
'
' Variable List
'
dim RSwDat, LastRSwDat,RRlyDat, ValvePos as byte
'
'******************************************************************************
' Main program
main:
'
'Initialize I/O - direction and value set on bit basis for clarity
' Outut bits set to appropriate initial state. Exception is Port D, used as
' an I/O port for bits 0-7, bits 12 & 13 outputs only, but held in default
' state in hardware when port is set as input.
'
AD1PCFG = 0xFFFF 'Set analog/digital pins to digital
JTAGEN_bit = 0 'Disable JTAG
' TRISA4_bit = 0 'These lines make no difference whether compiled or not
' LATA4_bit = 0 "
' TRISE6_bit = 0 "
' LATE6_bit = 0 "
' Delay_ms (1000) "
'
SPI2_Init_Advanced(_SPI_MASTER,_SPI_8_BIT, 4, _SPI_SS_DISABLE,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_ACTIVE_2_IDLE)
SPExpanderCS = 0
Spi_Lcd_Config(0) ' Initialize LCD over SPI interface
'
Spi_Lcd_Cmd(_LCD_CLEAR) ' Clear display
Spi_Lcd_Cmd(_LCD_CURSOR_OFF) ' Turn cursor off
Spi_Lcd_Out (1,1,"LIEBHERR Aerospace ") ' "
Spi_Lcd_Out (2,1,"LCD Debug Program ") ' "
Spi_Lcd_Out (3,1,"Pass # 1 ") ' "
Spi_Lcd_Out (4,1,"** In Development **") ' "
Delay_ms(3000)
' Program uses SPI2 module
'
This code is identical to that in the working program.

Please advise. Any suggestions you can give me would be apreciated.

hexreader
Posts: 1785
Joined: 27 Jun 2010 12:07
Location: England

Re: PIC32MX Clicker2 with SPI Serial LCD Adapter

#2 Post by hexreader » 18 Jul 2021 13:37

Nobody else seems to be replying, so I will give an educated guess:

Seems to me that this may be a voltage level issue.

The 2x16 and 4x20 LCD modules that I am familiar with require a 5 Volt supply. 3.3 Volts may be insufficient.

Even with 5V supply, some LCD modules work with 3.3V signal levels, other LCDs can be intermittent.

EDIT: I see no problem with the adapter, since MCP23S17 datasheet states voltage 1.8 to 5.5 OK.

In a perfect world, you would use a 5V supply on the LCD, and use level converters to give 5V signal levels. This makes for a very complicated circuit.

The ideal solution might be to find an adapter and LCD that is designed for 3.3V operation, if such a thing exists?

Disclaimer: these ideas are based on my limited experiences. The above may turn out to have no bearing on your problems.
Just putting ideas out there.... feel free to ignore
Start every day with a smile...... (get it over with) :)

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: PIC32MX Clicker2 with SPI Serial LCD Adapter

#3 Post by Thomas.Pahl@t-online.de » 19 Jul 2021 19:04

There must be some sort of oversight. Compare the two programs line for line.
what does this: SPExpanderCS = 0 ??

since the library controls chip select of the expander.

Terry.Stefanski
Posts: 23
Joined: 29 Jan 2016 21:13

Re: PIC32MX Clicker2 with SPI Serial LCD Adapter

#4 Post by Terry.Stefanski » 19 Jul 2021 19:55

Thanks for the reply, but that is not the issue.

* The LCD is powered by 5V, with Reset, Chip Select, Clock and MOSI outputs from the CPU are buffered. No outputs from the LCD are used, or connected. I have deployed this hardware several
times before, that are running with no problems.
* This specific hardware set runs a previous program, driving the LCD correctly.
* The LCD driver and communications routines in the new program are cut-and-paste from the program that works, checked line by line.
* If I load and run the previous program, then load my new program, the LCD runs fine, even after a CPU reset, a hardware LCD reset or a program recompile and re-upload. It runs fine until the
LDC is powered down.
* Unable to test if powering down the CPU only leaves the LCD operational, as the +3.3V is derived from +5V with an LDO regulator. The on-board power switch does not work because power is fed
in through the interface pins along the edges of the Clicker-2 board, plugged in a s mezzanine to the application-specific interface board.

Questions, comments ideas and wild guesses welcome. Getting frustrated...

Sincerely,
Terry Stefanski

Terry.Stefanski
Posts: 23
Joined: 29 Jan 2016 21:13

Re: PIC32MX Clicker2 with SPI Serial LCD Adapter

#5 Post by Terry.Stefanski » 19 Jul 2021 20:04

To answer the question regarding what does this: SPExpanderCS = 0, I had to add that to my previous program (the one that is working) to get it to talk to the LCD.

I have checked line by line, but I am going to make a working copy of the working program, and start stripping out code until the LCD stops working, then rebuild from there.

As before questions, comments and ideas welcome.

Thank you all for in advance for any help.

Terry Stefanski

Terry.Stefanski
Posts: 23
Joined: 29 Jan 2016 21:13

Re: PIC32MX Clicker2 with SPI Serial LCD Adapter

#6 Post by Terry.Stefanski » 29 Jul 2021 21:58

Greetings, All:

Problem solved: I had to insert the following code in the "MAIN" area to get the LCD to initialize:

TRISG6_bit = 0 'Set SPI SCK bit as output, state handled by driver
TRISG7_bit = 0 'Set SPI MOSI bit as output, state handled by driver

- But: -
if I included
TRISG4_bit = 0 'Set SPI CS bit as output, state handled by driver
it did not work

No idea as to why...

Terry Stefanski

Post Reply

Return to “mikroBasic PRO for PIC32 General”