SPI introduction and LCD introduction

Download Report

Transcript SPI introduction and LCD introduction

LCD programming
Design and implementation
details on the way to a valid
SPI-LCD interface driver
To be tackled today



How do you send commands from the
Blackfin to a LCD device?
What commands are necessary to
control the LCD device -- HD44780?
How do we get the timing correct?
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
2
Functions we have now
developed for Lab. 5






void Write_SPI_TDBR_ASM(ushort transmit_value);
•
Write the value “transmit_value” to SPI TDBR register
void ControlFLG5_ASM(ushort low_or_high)
•
•
Activates FLS5 (select flag 5 bit)
Sets FLG5 bit high or low as requested
void WaitWhileSPIF_ASM(ushort low_or_high);
•
Waits will SPI_STAT SPIF flag is low or high
void Set_SPIregisters_ASM(ushort BAUD_SCALE)
void Set_SIC_IMASK_ASM(ulong bit_to_set);
void WriteSPI(ushort value)  All we will need today
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
3
Master / Slave concept
Master to Slave data movement




Master sends out
information to slave on
MOSI wire
Slave receives
information from the
master on MOSI wire
SLAVE IGNORES
INFORMATION
UNLESS SLAVE
SELECT LINE IS
ACTIVE
Information (bits) is
clocked by SCLK
signal.
•
1-bit, 1 clock tick
7/18/2015
MOSI --MASTER OUT – SLAVE IN
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
4
Now at the stage where we can do
some experimenting with the
hardware

We know that the following pins are “key” to
the operation of the interface.
•


Place scope probes on these lines
MOSI – this will show the data being
transmitted from the SPI interface
PF5 – chip select line
•
•
When this is pulled low, then the slave will accept any
data being transmitted, otherwise data is ignored
When this goes – low to high – then the serial data
transmitted to the slave is “latched” (converted into a
parallel signal that is then sent to LCD as a data or a
command request.
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
5
Known facts -- MOSI data is
transmitted from Blackfin the moment
that data is written to SPI_TDBR
Blackfin Processor
SLAVE SELECT
PF5 used (PF0 to PF7)
MOSI
SPI
CLOCK
MISO
SLAVE OUTPUT INTERFACE
SLAVE INPUT INTERFACE
LOAD
Slave to
LCD
CONTROL
DATA
LCD SCREEN
7/18/2015
SWITCHES (LOGIC LAB)
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
6
Known facts -- MOSI data is accepted
by the SLAVE if slave-select is active
low – PF5 is low – Master/Slave
Blackfin Processor
SLAVE SELECT
PF5 used (PF0 to PF7)
MOSI
SPI
CLOCK
MISO
SLAVE OUTPUT INTERFACE
SLAVE INPUT INTERFACE
LOAD
Slave to
LCD
CONTROL
DATA
LCD SCREEN
7/18/2015
SWITCHES (LOGIC LAB)
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
7
Known facts – The SLAVE only sends the
data to the LCD when the PF5 line goes
from low to high – interface design
Blackfin Processor
SLAVE SELECT
PF5 used (PF0 to PF7)
MOSI
SPI
CLOCK
MISO
SLAVE OUTPUT INTERFACE
SLAVE INPUT INTERFACE
LOAD
Slave to
LCD
CONTROL
DATA
LCD SCREEN
7/18/2015
SWITCHES (LOGIC LAB)
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
8
Current Solutions and Problems
Change to C++ programs as no longer taking directly to the hardware
ClearScreen( ) { WriteSPI(0x0001); }
WriteLetter(char letter) {WriteSPI(0x0200
| letter);
Call CursorMoveASM}
CursorMove ( )
{ WriteSPI( 0x????); } etc
•How do we stop the LCD device from accepting too many commands?
•How do we know when the LCD device is ready for the next command?
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
9
ENABLE Signal
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
10
Enable signal


Enable signal works on the high-to-low
transition
Send required signal to interface means
•
•
•
Required signal + enable signal high
Wait long enough for voltages to “settle” (stabilize)
Required signal + enable signal low
•
Wait long enough for LCD command to work
•
Required signal + enable signal high
• This strobes the information into the LCD screen
• How long is “long enough”?
• Avoid “race” conditions to make sure that we don’t loose
the signal
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
11
Hooking up the LCD
WATCH OUT
DB lines are ordered L-to-R
LO to HIGH
But data bit connector lines are
labelled R-to-L
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
12
Blackfin transmits 16 bits with
THIS format
DB7, DB6, ………DB1, DB0
E – Enable / Strobe
RS
1  0 – When this line goes from high to the
low, then the command is send to (latched
into) LCD
1 – LCD data
0 – LCD instruction
R/W
1 – Read from LCD
0 – Write to LCD
7/18/2015
To make LCD respond to command 0x4F0
Then Blackfin must transmit
0x5F0 ( E High )
0x4F0 ( E low )
0x5F0 ( E high )
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
13
LCD Instruction set
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
14
Current Solutions -- Instruction
Change to C++ programs as no longer taking directly to the hardware
#define ENABLE_BIT 0x100
#define R_W_BIT 0x200
#define DATA_BIT 0x400
ClearScreen( ) {
#define ClearDisplayCommand 0x0001;
WriteSPI(ClearDisplayCommand | ENABLE_BIT);
Wait till voltages settle
WriteSPI(ClearDisplayCommand);
Wait for command to finish (1.64 ms – Lab 3 s, ms, us timer)
WriteSPI(ClearDisplayCommand | ENABLE_BIT);
}
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
15
Current Solutions -- Data
Change to C++ programs as no longer taking directly to the hardware
#define ENABLE_BIT 0x100
#define R_W_BIT 0x200
#define DATA_BIT 0x400
// Active low
WriteLetter( char letter) {
WriteSPI(letter | DATA_BIT | ENABLE_BIT);
Wait till voltages settle
WriteSPI(letter | DATA_BIT);
Wait for command to finish (40 us – Lab 3 s, ms, us timer)
WriteSPI(letter | DATA_BIT | ENABLE_BIT);
}
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
16
Some commands
LCD COMMANDS
ClearScreen( )
CursorIncrease( )
CursorMove( )
DisplayOn( )
WriteLetter(value)
WriteLetter(‘a’)
WriteLetter(‘A’)
7/18/2015
RS
R/W DATA DB7 to DB0
0
0
0
0
1
1
1
0
0
0
0
0
0
0
0x01
0x05
0x10
0x0B
value
0x61 (ascii ‘a’)
0x41 (ascii ‘A’)
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
17
SetUpDisplay( )

From the manual

Send command 0x30 – wait 4 ms
Send command 0x30 – wait 4 ms
Send command 0x3C – wait 4 ms
Send command 0x3C – wait 4 ms




Don’t forget to send the command to “activate
the screen” -- LCDDisplay(ushort On_or_OFF);
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
18
You write the code for


LCDDisplay(ushort On_or_OFF);
CursorMove(ushort left_or_right);
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
19
This was the solution of writing
“Hello” to LCD
SetUpDisplay( );
General concept was there,
EnableDisplay( );
ClearDisplay( );
UseFixedTimeASM( );
CursorIncrease( );
UseFixedTimeASM( );
DisplayOn( );
Use FixedTimeASM( );
WriteLetter(‘H’);
UseFixedTimeASM( );
CursorMove( );
UseFixedTimeASM( );
WriteLetter(‘e’);
etc.
Now fix the solution to write
7/18/2015
“Happy Christmas” to LCD screen
Except for the wiring and demo
Lab. 5 is essentially done
Note: As of 24th October the
SPI interface was unstable
for input to Blackfin
DON’T connect input interface
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
20
Details of what is needed
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
21
Data to send a character




Complicated or not?
To cause “A” to appear on
LCD screen need bit
pattern 01000001 = 0x41
sent to LCD data pins
Also send the necessary
LCD control signals
How do the letter bit
patterns for the LCD data
patterns relate to ASCII bit
patterns?
•
standard format used to
store characters in a C++
character array?
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
22
Now complete part of Lab. 4
LCD as video screen

Now play the video game by moving the
cursor on the LCD screen
• Minimum requirements
• Move the cursor in response to temperature
•
•
changes
Print “player 1” wins if cursor moves all the
way to the right
Print “player 2” wins if cursor moves all the
way to the left
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
23

Information taken from Analog Devices On-line
Manuals with permission
http://www.analog.com/processors/resources/technicalLibrary/manuals/

Information furnished by Analog Devices is believed to be
accurate and reliable. However, Analog Devices assumes no
responsibility for its use or for any infringement of any patent
other rights of any third party which may result from its use. No
license is granted by implication or otherwise under any patent
or patent right of Analog Devices. Copyright  Analog
Devices, Inc. All rights reserved.
7/18/2015
SPI and LCD
,
Copyright M. Smith, ECE, University of Calgary, Canada
24