Cascading Dot Matrix and STM32

Description

100%
100%

Some time ago, we did interface a dot matrix display with STM32. Today in this tutorial I am going to show you guys How to program Dot matrix displays in cascade using STM32. I will also show you guys how to scroll a single character or the entire string in different direction. I am using STM32f103c8 microcontroller and FC16 MAX7219 Dot matrix Displays, which I found using MD_MAX72XX library for arduino.

In order to connect the displays in cascading mode, the data output pin (Dout) of one is connected to data input pin (Din) of the other display. All the displays are connected to the same CS pin. Now to write data to the display I have written a library and in this tutorial, I am going to go through some functions and their usage.

How to

Ok so after generating the code through CubeMx, next step is to include the library and to do that, put the max_matrix_stm32.h in the inc folder and put max_matrix_stm32.c in the src folder.
First of all we need to change few details in the max_matrix_stm32.h file and they are as follows

// change the max7219 PORT and Pins below
#define maxport GPIOA
#define data_Pin GPIO_PIN_2
#define cs_Pin GPIO_PIN_3
#define clock_Pin GPIO_PIN_4


// Set the number of dot-matrix-displays being used
#define num 4 

maxport : is the common port for all the pins that are being used in the display
data_pin : the pin, Data pin is connected to
and same for the cs_pin and clock_pin
num : the number of displays connected in cascade

Now let’s initiate the displays. The following function initialises the connected displays with the brightness varying from 1-15.

void max_init (uint8_t brightness);

Next we are going to write a character on the display and to do that we have the following function

void write_char (char c, uint8_t max)

It takes 2 parameters:
‘c’ : is the character to write
‘max’ : is the number of the dot matrix display, where you want to write the character. This should start with 1.

write_char ('A',4);  // write 'A' on 4th display
write_char ('2',3);  // write '2' on 3rd display
write_char (3,2);  // print heart on 2nd display
write_char ('m',1);  // write 'm'on st display

In order to write a character with left scroll or right scroll effects, the following function is used.

void scroll_char (char c, uint32_t speed, char direction) 

It takes three parameters:
‘c’ : is the character which you want to shift
‘speed’ : is the time delay in ms between each shift
‘direction’ : is the direction of the shift. This value can only be either left or right

Scrolling the entire string is also same as shifting a character.

void shift_string (uint8_t *string, uint32_t speed, char direction)

The above function takes 3 parameters:
‘*string’ : Pointer to the string that you want to shift on the display. If you want to input the string directly, you have to type convert it eg- (uint8_t *) “string here”.
speed and direction are mentioned above.

YOU CAN DOWNLOAD FULL CODE AT THE END OF THIS POST

You can check the rest of the functions in the **.h file and the **.c file itself. The code is commented properly so that you guys can understand it.

100%
100%

Result

100%
100%
Check out the VIDEO Below
100%
100%

DOWNLOAD

You can buy me a coffee sensor ūüôā

download the CODE below

100%
100%
, , , , , , , , , ,

9
Leave a Reply

avatar
5 Comment threads
4 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
5 Comment authors
KielBonotadminRompelWojciech Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Wojciech
Guest
Wojciech

Hey, how should I connect it?

Rompel
Guest
Rompel

reallly nice tutorial on dealing with max7219. i use your code and it works really well and i update it to my own purpose.

Could you please do one tutorial with spi-interface? because i try it by changing your code but it is not working. I will really be delighted to get because i want to change the MAX7219 with tlc5940 and use transistor which will also be controlled with the same spi-interface.

delight for reply and keep on doing it is really useful

Rompel
Guest
Rompel

I just saw it. By struggling in the code, I do not really understand your setrow() and setled() function, could you please add more comment to ease comprehension? do you have an easier way coding the shifter 4x(8×8) LED withoug th setled and setrow() function, such that i will get a better understanding of your step?

Bonot
Guest
Bonot

Could you give an idea how to display different languages. Like Hindi, Chinese ….

Kiel
Guest
Kiel

I can display different language character but it can not scroll the string.Could you give me idea.

Menu