Cascading Dot Matrix and STM32

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 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.






Result

Check out the Video Below










Info

You can help with the development by DONATING
To download the code, click DOWNLOAD button and view the Ad. The project will download after the Ad is finished.

12 Comments. Leave new

  • Hi is it possible to do the same you did but using SPI communication?
    Best regards

    Reply
  • Hi i want to know how can control the Dot Matrix with SPI? if possible a tutorial would be great

    Reply
  • Hey. thanks for your lessons! do a lesson on 4-bit led digital tube module 74hc595
    
    Reply
  • I can display different language character but it can not scroll the string.Could you give me idea.

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

    Reply
  • 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?

    Reply
  • 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

    Reply
  • Hey, how should I connect it?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

keyboard_arrow_up

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add controllerstech.com to your ad blocking whitelist or disable your adblocking software.

×