0:09
hello and welcome to controllers Tech
0:12
today in this video we will see how to
0:15
interface the LED do Matrix with SDM
0:18
32 we will use the SBI peripheral of the
0:21
SDM 32 to do so this video will focus on
0:26
a single 8x8 do Matrix display which is
0:29
connected with either Max
0:31
7219 or 7221 I's although I don't have a
0:36
separate single display module so I will
0:39
use this one it has four display modules
0:42
cascaded together but still we will only
0:45
focus on this particular one just ignore
0:48
what's going on with the rest three and
0:50
only focus on the first one if you have
0:53
ever tried interfacing these modules you
0:56
might have come across their types there
0:58
are different libraries for each type
1:00
for example fc16 parola IC station
1:05
generic Etc in this video we will not
1:08
focus on any type of Hardware rather we
1:10
will write the code according to how it
1:12
displayed the output I don't know the
1:15
type I have so I will write my code
1:17
based on trials and errors you will
1:21
understand it in a while there is a good
1:23
article on Arduino Plus+ which explains
1:27
the reasons for these different types
1:29
and what are the differences between
1:31
them basically these Max 7219 and 7221
1:36
ic's are originally designed for the
1:38
seven segment displays so they are
1:40
capable of controlling the 64 individual
1:44
LEDs however there are no standards for
1:46
mapping the 64 LEDs into rows and
1:50
columns therefore depending on Hardwares
1:53
either the rows or columns can be wired
1:56
digits also their increasing order is un
2:00
certain the point is no matter what
2:03
Hardware you have you will be able to
2:05
display characters on it the only issue
2:08
you will face is either the characters
2:11
will be mirrored horizontally or
2:13
vertically or they might be
2:15
rotated in this tutorial we will see how
2:20
issues as I mentioned I don't know what
2:23
Hardware type I have so I will prepare
2:25
my library based on some trials and
2:28
errors here is the data sheet for the
2:32
display this is not an official one for
2:36
7219 but it is smaller in size and it
2:42
information the device requires 5 volts
2:45
and you should provide the voltage
2:47
externally this is because there are a
2:50
lot of LEDs and they will consume a lot
2:53
current this might damage the MCU so it
2:57
is better to provide the voltage using a
2:59
battery or by some other
3:01
means let's take a look at the
3:03
connection before proceeding
3:05
ahead here is how the display module is
3:08
connected to the SDM 32 f103
3:12
MCU the pin pa7 is the mossy pin which
3:16
is connected to the data of the
3:19
device pa5 is the clock pin and it is
3:23
connected to the clock pin of the
3:25
device pa4 is the Cs pin and it is
3:29
connected to the Cs pin of the
3:31
device the display is powered from a 5vs
3:35
battery as I mentioned before it is
3:38
advised to use the external power source
3:42
display this is because the LEDs will
3:45
consume a lot of current and this might
3:49
MCU let's continue with the data sheet
3:52
of the device I will just cover the
3:54
important points from this data sheet
3:57
here you can see the serial data format
4:01
the device works with 16bit data
4:03
transfer out of these 16 bits only 12
4:07
bits are usable out of these 12 bits the
4:11
higher four bits are the address bits
4:13
and the rest eight are the data bits
4:17
just keep this in mind as we will set up
4:19
our project according to this we will
4:22
check the rest of the data sheet later
4:24
let's start the cube ID and create a new
4:28
project I am using the SDM 32 f103
4:33
C8 give some name to the project and
4:36
click finish let's start with the clock
4:40
setup first I am choosing the external
4:43
high-speed Crystal to provide the clock
4:46
the blue pill board has 8 MHz Crystal on
4:49
it and we will use the PLL to run the
4:54
mahz now go to CIS debug and enable
4:58
serial wire now we will enable the SBI 1
5:02
in the half duplex mode we don't need to
5:05
receive any data from the slave device
5:07
so half duplex mode is fine here you can
5:11
see that the clock and mossy pins have
5:15
automatically we need to manually enable
5:17
the chip select pin so set the pin pa4
5:20
as output let's rename it to
5:23
CS we only need three pins from the MCU
5:28
let's configure the parameters now now
5:30
let's set the data size to 16 bits and
5:33
the data should be sent in the order
5:35
most significant bit first there is no
5:39
particular requirement for the board
5:40
rate so I will keep it around 2 megabits
5:43
per second make sure that the clock
5:46
polarity is set to high basically the
5:49
clock should be high when it is Idle
5:51
this is the requirement in the max 7219
5:55
data sheet now go to the gpio
6:00
and set the default state of the Cs pin
6:02
to high this will keep the slave
6:05
disabled by default that is all the
6:08
configuration we need click save to
6:10
generate the project now we need to
6:13
initialize the device first and here are
6:16
the available registers on Max
6:20
7219 here the first eight registers are
6:22
for writing the data into the respective
6:25
column and the next few registers are
6:28
for initializing the display the decode
6:31
mode register with the address 9 hex
6:34
decides whether you want to use the code
6:36
B fonts these fonts are designed
6:39
specially for the seven segment display
6:42
writing zero to this register disables
6:45
the decode mode we should keep it
6:48
disabled while using the dot matrix
6:50
display next we have the intensity
6:53
register which decides how brighter the
6:55
display will be the higher the duty
7:00
the brighter are the LEDs but they also
7:02
consume more current so choose this
7:06
value keeping the current consumption in
7:08
mind next is the scan limit register
7:12
this register decides how many columns
7:14
we want to enable our display consists
7:17
of eight rows and eight columns so we
7:20
will enable all of them then we have a
7:23
shutdown register writing zero to this
7:26
register shuts the display down and
7:28
writing a one in enables the normal
7:31
operation at last we have the display
7:33
test register which is again used in the
7:36
seven segment display so we will keep it
7:39
disabled too we need to write the values
7:43
we discussed into these registers to do
7:46
that we will Define a new function the
7:49
parameters of this function will be the
7:52
address where we want to write and the
7:54
data what we want to write now as we
7:57
already discussed the device expect the
7:59
data in a 12-bit format with address
8:02
bits being the higher four bits
8:05
therefore we will Define a new 16bit
8:07
variable where we will store the address
8:09
and data combined together the address
8:12
bits should be at the higher positions
8:15
so shift them left by eight places and
8:17
then add the result with the data bite
8:20
if you notice the register addresses
8:22
they are actually 4 bit in size
8:26
therefore our 16bit variable actually
8:28
contains 12 bit useful data which is as
8:31
expected by the slave device now we will
8:35
send this data to the slave device to do
8:38
so first pull the Cs pin low so to
8:41
enable the slave device then call the
8:44
function hall SB I transmit to transmit
8:47
the data in the Blocking Mode here the
8:50
data expected by the function is the
8:52
pointer to the 8 bit unsigned array so
8:55
we will pass the address of the 16-bit
9:00
after transmitting the data disable the
9:02
slave by pulling the Cs pin high again
9:06
now let's define another function to
9:08
initialize the dot matrix display here
9:11
we will write the data to these
9:14
registers let's start with disabling the
9:16
decode mode write the data zero to the
9:20
register 9 hex next we have the
9:23
intensity register I will keep it low so
9:27
I need to write a one to this register
9:32
next is the scan limit register at the
9:36
beex here we want to enable all columns
9:39
so we will write the value seven to this
9:42
register next we have the shutdown
9:45
register at the address
9:46
CeX we want the device in the normal
9:49
operation mode so write a one to this
9:55
register at last we have the display
9:57
test register at the address F hex write
10:01
a zero to this register so to disable
10:07
test so that is all for the
10:09
initialization let's call this function
10:12
inside the main function all right now
10:15
we will write some data to the device we
10:18
have the eight columns to write the data
10:20
into and their address ranges from 1 hex
10:22
to 8 hex the data will also be sent in
10:26
the similar manner with the higher four
10:28
bits being the column address followed
10:30
by the data itself let's assume I want
10:34
to write the data one to column one you
10:37
can see the display on the bottom right
10:39
corner of the screen just focus on the
10:42
first display and ignore what's going on
10:45
with the rest of them you can see
10:47
everything is random on the display
10:50
although just take a look at the last
10:52
row there is only the first led turned
10:54
on and this is as for the data we sent
10:58
the rest of them are r
10:59
because we did not write any data to
11:01
them so whenever we are writing data we
11:04
must write to all the eight columns
11:07
let's write a new for Loop which will be
11:09
used to send data to all the eight
11:12
columns inside this Loop we will send
11:15
different values to each column
11:18
basically the value in column one will
11:20
be one column two will be two and column
11:23
8 will be8 you can see the result on the
11:27
display according to the output on the
11:30
display our column one is this Row in
11:32
the end and the data is being written
11:34
from left to right column 1 has the
11:37
value one therefore only the first led
11:40
is on then column two has the value two
11:44
therefore only the second LED is on then
11:48
column 3 has the value two therefore
11:51
both the first and second LEDs are on
11:54
you can see the rest of the columns also
11:56
follow the same rule so now it is clear
11:59
that the columns are increasing from
12:01
bottom to top and the data is being
12:03
displayed from left to right remember
12:06
that this depends on how you are viewing
12:09
the display if I rotate the display 90°
12:13
my rows become columns and columns
12:15
become rows that is not the point here
12:19
we just want the display to print values
12:21
according to our reference so for the
12:24
rest of the video please keep in mind
12:26
that the reference is how you are seeing
12:28
it right now now I don't really care if
12:31
the display is rotated or if I should
12:33
view it from a different angle now we
12:36
need a tool to generate the data for the
12:39
characters we can do it ourselves also
12:42
but it will be very time
12:44
consuming here is the tool which can do
12:47
the job perfectly set the width and
12:50
height to eight bite order to column
12:52
major and big endian I don't know if
12:56
these settings are correctors for the
12:57
display so we will first test them here
13:01
the great pixels are the ones which we
13:03
want to turn on click generate to
13:06
generate the code if you note the values
13:10
they are written according to the
13:12
columns but for us the columns are
13:14
actually the rows the two starting from
13:17
the bottom so this is definitely not
13:20
what we are looking for let's change the
13:23
bite order to R major now the data is a
13:27
little more convenient but it is
13:29
starting from the top you can see the
13:32
value f8 hex it is the second row from
13:35
the top then there are three empty rows
13:38
and then we have the value F XX as I
13:42
already mentioned our columns start from
13:45
the bottom but we can still work with
13:47
this data let's copy it and paste it in
13:53
code now inside the F Loop we will pass
13:56
these data values to the display
13:59
since the value of I is starting from
14:01
one we need to subtract one here so that
14:04
the data element can start from zero
14:07
let's flash it to the board to see the
14:10
output you can see the output is not
14:12
quite what we were expecting there are
14:15
two issues with the output data the
14:18
first is that the data is being written
14:20
from right to left and the second is
14:23
that the smaller row should be on the
14:25
top but here it is at the bottom the
14:28
second issue is understandable this is
14:31
because the values are generated in a
14:33
way that the columns are increasing from
14:35
top to bottom but we wanted the other
14:37
way around so instead of passing the
14:40
first element to the First Column we
14:42
will reverse the order we will pass the
14:45
eighth element to the First Column
14:47
seventh to the second and therefore
14:49
first element to the eighth column let's
14:53
see the output on the display the second
14:56
issue has been resolved with this the
14:59
smaller row is on the top now the first
15:02
issue Still Remains though the column
15:04
data is being written from right to left
15:08
let's change the endianness to little
15:10
endian and generate the code copy it to
15:14
the project and let's see the output on
15:16
the display you can see that we got
15:19
exactly the same data that we drew in
15:21
the tool now we have got the
15:24
configuration for the display I am using
15:27
there are three major things here the
15:29
bite order should be R major little
15:31
endian and we should send the last bite
15:34
first let's say I want to print this
15:37
smiley on the display the configuration
15:40
is the same so let's just copy the
15:42
generated data into our project now
15:46
build and Flash the project to the board
15:49
you can see the same smiley face printed
15:51
on the display so we can now create any
15:55
character to print on the display you
15:58
can generate the entire array of the
16:00
characters and if you have any doubt you
16:02
can just refer to some display picture
16:05
for example if I want to print the
16:07
number three I will simply design it
16:10
here then copy it to the project and
16:12
display it I did generate the array of
16:15
numbers while I was testing the display
16:19
here you can see the data for the
16:20
numbers ranging from 0 to 9 the variable
16:24
Char data is a matrix with some rows and
16:29
now we will write another function
16:31
Matrix data which will print the number
16:34
on the display the parameter of this
16:36
function will be the number that we want
16:39
print here we will again write the F
16:42
Loop and inside it we will send the
16:44
datab bytes from the array we defined
16:47
the datab bytes will depend on the
16:49
number we want to print the array is
16:52
arranged in such a way that the row
16:54
element of the array contains the data
16:56
bites for the respective number for
16:59
example row zero contains the data for
17:01
the number zero and row six contains the
17:04
data for the number six so here we just
17:08
need to pass the numb parameter to the
17:10
row of the array the column contains the
17:13
eight data bytes and we will send them
17:15
in descending order now inside the while
17:18
loop let's write another for Loop which
17:21
will send the numbers from 0 to 9 each
17:24
number will be printed after a delay of
17:29
all right let's build and Flash the
17:31
project to our board you can see the
17:34
numbers from 0 to 9 are printed on the
17:39
milliseconds and after the number nine
17:41
there is a delay of 1 second so
17:44
everything is working as expected we are
17:47
able to interface The Matrix display
17:50
with the SDM 32 using the SPI peripheral
17:54
note that I still don't know the type of
17:56
display Hardware I have but using using
17:59
some trial and error we were able to
18:01
make it work we will continue the rest
18:04
in the next video where we will Cascade
18:06
the rest of the displays and finally
18:08
write the code to control all four of
18:13
today you can download the project from
18:18
description leave comments in case of
18:20
any doubt keep watching and have a nice