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.
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
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.
Next we are going to write a character on the display and to do that we have the following function
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.
In order to write a character with left scroll or right scroll effects, the following function is used.
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.
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.
- Interface WS2812 with STM32 April 16, 2021
- PWM with DMA in STM32 April 8, 2021
- Control Stepper motor using Rotary Angle Sensor March 21, 2021
- External Interrupt using Registers March 17, 2021
- STM32F103 Clock Setup using Registers March 3, 2021
- STM32 I2C Configuration using Registers February 26, 2021