matriz 8X8 SPI

Dependencies:   MAX7219 mbed

Fork of Nucleo_blink_led by Miguel Castañeda

Funcionamiento matriz 8X8 SPI con integrado MAX7219 utilizando tarjeta NUCLEO-FR446RE

Materiales:

  • Tarjeta NUCLEO-FR446RE
  • Módulo Matriz 8X8 con integrado MAX7219
  • Jumpers
  • Cable de conexión usb/miniusb

/media/uploads/miguelmstein/20170316_101022.jpg

Pines utilizados:

  • VCC - 5V
  • GND - GND
  • DIN - SPI3_MOSI / PC_12
  • CS - SPI1_SSEL / PA_15
  • CLK - SPI3_SCLK

/media/uploads/miguelmstein/20170316_100825.jpg

Procedimiento

  • Se conectaron los pines del módulo de la matriz al pinout de la tarjeta utilizando los jumpers hembra/hembra.
  • Se conecto el cable de alimentación y de trasnferencia de datos.
  • Luego con el código siguiente se compiló y se extrajo el archivo .bin que se copio a la carpeta de la tarjeta.

Video del montaje con el programa

/media/uploads/miguelmstein/20170316_091054.mp4

  • Nota: El código base se extrajo de un foro de mbed sobre como utilizar una matriz 8x8 con SPI y MAX7219.

Link del foro: https://developer.mbed.org/forum/mbed/topic/129/

  • Nota: El código fue modificado para funcionar con una sola matriz. El código se tradujo y cada funcion se explica en español. Con este código se puede mostrar dentro de lo posible lo que se quiera en una matriz de LEDs de 8x8 ya sea dígitos, letras, figuras, entre otros. Para modificar lo que se quiere mostrar basta con modificar el ultimo digito de cada columna en el código especificada.
Committer:
miguelmstein
Date:
Thu Mar 16 14:26:03 2017 +0000
Revision:
2:163373cf2b79
Parent:
1:1f5dc3c1d540
Child:
3:60bc310c772b
funcionamiento matriz 8x8 SPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
miguelmstein 0:97b0a853130e 1 #include "mbed.h"
miguelmstein 1:1f5dc3c1d540 2 #include "max7219.h"
miguelmstein 1:1f5dc3c1d540 3
miguelmstein 1:1f5dc3c1d540 4 // PC_12: DIN, PC_10: CLK, PA_15: LOAD/CS
miguelmstein 1:1f5dc3c1d540 5 SPI max72_spi(PC_12, NC, PC_10);
miguelmstein 1:1f5dc3c1d540 6 DigitalOut load(PA_15);
miguelmstein 1:1f5dc3c1d540 7
miguelmstein 1:1f5dc3c1d540 8 // define registros de matriz MAX7219
miguelmstein 1:1f5dc3c1d540 9 #define max7219_reg_noop 0x00
miguelmstein 1:1f5dc3c1d540 10 #define max7219_reg_digit0 0x01
miguelmstein 1:1f5dc3c1d540 11 #define max7219_reg_digit1 0x02
miguelmstein 1:1f5dc3c1d540 12 #define max7219_reg_digit2 0x03
miguelmstein 1:1f5dc3c1d540 13 #define max7219_reg_digit3 0x04
miguelmstein 1:1f5dc3c1d540 14 #define max7219_reg_digit4 0x05
miguelmstein 1:1f5dc3c1d540 15 #define max7219_reg_digit5 0x06
miguelmstein 1:1f5dc3c1d540 16 #define max7219_reg_digit6 0x07
miguelmstein 1:1f5dc3c1d540 17 #define max7219_reg_digit7 0x08
miguelmstein 1:1f5dc3c1d540 18 #define max7219_reg_decodeMode 0x09
miguelmstein 1:1f5dc3c1d540 19 #define max7219_reg_intensity 0x0a
miguelmstein 1:1f5dc3c1d540 20 #define max7219_reg_scanLimit 0x0b
miguelmstein 1:1f5dc3c1d540 21 #define max7219_reg_shutdown 0x0c
miguelmstein 1:1f5dc3c1d540 22 #define max7219_reg_displayTest 0x0f
miguelmstein 1:1f5dc3c1d540 23
miguelmstein 1:1f5dc3c1d540 24 #define LOW 0
miguelmstein 1:1f5dc3c1d540 25 #define HIGH 1
miguelmstein 1:1f5dc3c1d540 26 #define MHZ 1000000
miguelmstein 1:1f5dc3c1d540 27
miguelmstein 1:1f5dc3c1d540 28 void maxSingle( int reg, int col) {
miguelmstein 1:1f5dc3c1d540 29 //maxSingle es la funcion facil para usar una sola matriz max7219
miguelmstein 1:1f5dc3c1d540 30 load = LOW; // comienza
miguelmstein 1:1f5dc3c1d540 31 max72_spi.write(reg); // especifica registro
miguelmstein 1:1f5dc3c1d540 32 max72_spi.write(col); // coloca datos
miguelmstein 1:1f5dc3c1d540 33 load = HIGH; // acegura que los datos estan cargados(en el cambio en alto de LOAD/CS)
miguelmstein 1:1f5dc3c1d540 34 }
miguelmstein 1:1f5dc3c1d540 35
miguelmstein 1:1f5dc3c1d540 36 void setup () {
miguelmstein 1:1f5dc3c1d540 37 // iniciacion de la matriz MAX7219
miguelmstein 1:1f5dc3c1d540 38 // configuracion SPI : 8 bits, modo 0
miguelmstein 1:1f5dc3c1d540 39 max72_spi.format(8, 0);
miguelmstein 1:1f5dc3c1d540 40
miguelmstein 1:1f5dc3c1d540 41 // frecuencia MAX7219(10 MHZ)
miguelmstein 1:1f5dc3c1d540 42
miguelmstein 1:1f5dc3c1d540 43 maxSingle(max7219_reg_scanLimit, 0x07);
miguelmstein 1:1f5dc3c1d540 44 maxSingle(max7219_reg_decodeMode, 0x00); // usando una matriz led (sin digitos)
miguelmstein 1:1f5dc3c1d540 45 maxSingle(max7219_reg_shutdown, 0x01); // no para modo apagado
miguelmstein 1:1f5dc3c1d540 46 maxSingle(max7219_reg_displayTest, 0x00); // no test de display
miguelmstein 1:1f5dc3c1d540 47 for (int e=1; e<=8; e++) { // registros vacios, apaga todos los LEDs
miguelmstein 1:1f5dc3c1d540 48 maxSingle(e,0);
miguelmstein 1:1f5dc3c1d540 49 }
miguelmstein 2:163373cf2b79 50 maxSingle(max7219_reg_intensity, 0x03 & 0x0f); // con el primer registro se cambia intensidad luminica de la matriz. rango: 0x00 a 0x0f
miguelmstein 1:1f5dc3c1d540 51 }
miguelmstein 1:1f5dc3c1d540 52 int t;
miguelmstein 0:97b0a853130e 53 int main() {
miguelmstein 1:1f5dc3c1d540 54 setup ();
miguelmstein 1:1f5dc3c1d540 55 while (1){
miguelmstein 2:163373cf2b79 56 if(t<=200)
miguelmstein 2:163373cf2b79 57 {
miguelmstein 2:163373cf2b79 58 maxSingle(1,255); //columna 1
miguelmstein 2:163373cf2b79 59 maxSingle(2,129); //columna 2
miguelmstein 2:163373cf2b79 60 maxSingle(3,129); //columna 3
miguelmstein 2:163373cf2b79 61 maxSingle(4,129); //columna 4
miguelmstein 2:163373cf2b79 62 maxSingle(5,129); //columna 5
miguelmstein 2:163373cf2b79 63 maxSingle(6,129); //columna 6
miguelmstein 2:163373cf2b79 64 maxSingle(7,129); //columna 7
miguelmstein 2:163373cf2b79 65 maxSingle(8,255); //columna 8
miguelmstein 2:163373cf2b79 66 }
miguelmstein 2:163373cf2b79 67 else if(t>=201&&t<=400)
miguelmstein 2:163373cf2b79 68 {
miguelmstein 2:163373cf2b79 69 maxSingle(1,0); //columna 1
miguelmstein 2:163373cf2b79 70 maxSingle(2,126); //columna 2
miguelmstein 2:163373cf2b79 71 maxSingle(3,66); //columna 3
miguelmstein 2:163373cf2b79 72 maxSingle(4,66); //columna 4
miguelmstein 2:163373cf2b79 73 maxSingle(5,66); //columna 5
miguelmstein 2:163373cf2b79 74 maxSingle(6,66); //columna 6
miguelmstein 2:163373cf2b79 75 maxSingle(7,126); //columna 7
miguelmstein 2:163373cf2b79 76 maxSingle(8,0);
miguelmstein 2:163373cf2b79 77 }
miguelmstein 2:163373cf2b79 78 else if(t>=401&&t<=600)
miguelmstein 2:163373cf2b79 79 {
miguelmstein 2:163373cf2b79 80
miguelmstein 2:163373cf2b79 81 maxSingle(1,0); //columna 1
miguelmstein 2:163373cf2b79 82 maxSingle(2,0); //columna 2
miguelmstein 2:163373cf2b79 83 maxSingle(3,60); //columna 3
miguelmstein 2:163373cf2b79 84 maxSingle(4,36); //columna 4
miguelmstein 2:163373cf2b79 85 maxSingle(5,36); //columna 5
miguelmstein 2:163373cf2b79 86 maxSingle(6,60); //columna 6
miguelmstein 2:163373cf2b79 87 maxSingle(7,0); //columna 7
miguelmstein 2:163373cf2b79 88 maxSingle(8,0); //columna 8
miguelmstein 2:163373cf2b79 89
miguelmstein 2:163373cf2b79 90 }
miguelmstein 2:163373cf2b79 91 else if(t>=601&&t<=800)
miguelmstein 1:1f5dc3c1d540 92 {
miguelmstein 1:1f5dc3c1d540 93 maxSingle(1,0); //columna 1
miguelmstein 1:1f5dc3c1d540 94 maxSingle(2,0); //columna 2
miguelmstein 1:1f5dc3c1d540 95 maxSingle(3,0); //columna 3
miguelmstein 2:163373cf2b79 96 maxSingle(4,24); //columna 4
miguelmstein 2:163373cf2b79 97 maxSingle(5,24); //columna 5
miguelmstein 1:1f5dc3c1d540 98 maxSingle(6,0); //columna 6
miguelmstein 1:1f5dc3c1d540 99 maxSingle(7,0); //columna 7
miguelmstein 1:1f5dc3c1d540 100 maxSingle(8,0); //columna 8
miguelmstein 2:163373cf2b79 101
miguelmstein 1:1f5dc3c1d540 102 }
miguelmstein 2:163373cf2b79 103 else if(t>=801&&t<=1000)
miguelmstein 1:1f5dc3c1d540 104 {
miguelmstein 2:163373cf2b79 105 maxSingle(1,0); //columna 1
miguelmstein 2:163373cf2b79 106 maxSingle(2,0); //columna 2
miguelmstein 2:163373cf2b79 107 maxSingle(3,60); //columna 3
miguelmstein 2:163373cf2b79 108 maxSingle(4,36); //columna 4
miguelmstein 2:163373cf2b79 109 maxSingle(5,36); //columna 5
miguelmstein 2:163373cf2b79 110 maxSingle(6,60); //columna 6
miguelmstein 2:163373cf2b79 111 maxSingle(7,0); //columna 7
miguelmstein 2:163373cf2b79 112 maxSingle(8,0); //columna 8
miguelmstein 2:163373cf2b79 113
miguelmstein 2:163373cf2b79 114 }
miguelmstein 2:163373cf2b79 115 else if(t>=1001&&t<=1200)
miguelmstein 2:163373cf2b79 116 {
miguelmstein 2:163373cf2b79 117
miguelmstein 2:163373cf2b79 118 maxSingle(1,0); //columna 1
miguelmstein 2:163373cf2b79 119 maxSingle(2,126); //columna 2
miguelmstein 2:163373cf2b79 120 maxSingle(3,66); //columna 3
miguelmstein 2:163373cf2b79 121 maxSingle(4,66); //columna 4
miguelmstein 2:163373cf2b79 122 maxSingle(5,66); //columna 5
miguelmstein 2:163373cf2b79 123 maxSingle(6,66); //columna 6
miguelmstein 2:163373cf2b79 124 maxSingle(7,126); //columna 7
miguelmstein 2:163373cf2b79 125 maxSingle(8,0);
miguelmstein 1:1f5dc3c1d540 126
miguelmstein 1:1f5dc3c1d540 127 }
miguelmstein 1:1f5dc3c1d540 128 else if(t>=12001&&t<=16000)
miguelmstein 1:1f5dc3c1d540 129 {
miguelmstein 2:163373cf2b79 130
miguelmstein 2:163373cf2b79 131 maxSingle(1,255); //columna 1
miguelmstein 2:163373cf2b79 132 maxSingle(2,129); //columna 2
miguelmstein 2:163373cf2b79 133 maxSingle(3,129); //columna 3
miguelmstein 2:163373cf2b79 134 maxSingle(4,129); //columna 4
miguelmstein 2:163373cf2b79 135 maxSingle(5,129); //columna 5
miguelmstein 2:163373cf2b79 136 maxSingle(6,129); //columna 6
miguelmstein 2:163373cf2b79 137 maxSingle(7,129); //columna 7
miguelmstein 2:163373cf2b79 138 maxSingle(8,255); //columna 8
miguelmstein 2:163373cf2b79 139
miguelmstein 2:163373cf2b79 140 }
miguelmstein 2:163373cf2b79 141 else if(t>=1601&&t<=1800)
miguelmstein 2:163373cf2b79 142 {
miguelmstein 2:163373cf2b79 143 maxSingle(1,255); //columna 1
miguelmstein 2:163373cf2b79 144 maxSingle(2,129); //columna 2
miguelmstein 2:163373cf2b79 145 maxSingle(3,129); //columna 3
miguelmstein 2:163373cf2b79 146 maxSingle(4,129); //columna 4
miguelmstein 2:163373cf2b79 147 maxSingle(5,129); //columna 5
miguelmstein 2:163373cf2b79 148 maxSingle(6,129); //columna 6
miguelmstein 2:163373cf2b79 149 maxSingle(7,129); //columna 7
miguelmstein 2:163373cf2b79 150 maxSingle(8,255); //columna 8
miguelmstein 2:163373cf2b79 151
miguelmstein 1:1f5dc3c1d540 152 }
miguelmstein 1:1f5dc3c1d540 153
miguelmstein 2:163373cf2b79 154 else{
miguelmstein 2:163373cf2b79 155 }
miguelmstein 2:163373cf2b79 156
miguelmstein 1:1f5dc3c1d540 157 t=t+1;
miguelmstein 2:163373cf2b79 158 if(t>=1800)
miguelmstein 1:1f5dc3c1d540 159 t=0;
miguelmstein 1:1f5dc3c1d540 160 else{}
miguelmstein 1:1f5dc3c1d540 161 }
miguelmstein 1:1f5dc3c1d540 162 }