matriz 8X8 SPI
Fork of Nucleo_blink_led by
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
Pines utilizados:
- VCC - 5V
- GND - GND
- DIN - SPI3_MOSI / PC_12
- CS - SPI1_SSEL / PA_15
- CLK - SPI3_SCLK
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.
main.cpp@1:1f5dc3c1d540, 2017-03-15 (annotated)
- Committer:
- miguelmstein
- Date:
- Wed Mar 15 23:48:50 2017 +0000
- Revision:
- 1:1f5dc3c1d540
- Parent:
- 0:97b0a853130e
- Child:
- 2:163373cf2b79
p1; ; ;
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:1f5dc3c1d540 | 50 | maxSingle(max7219_reg_intensity, 0x00 & 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 | 1:1f5dc3c1d540 | 56 | if(t<=2000) |
miguelmstein | 1:1f5dc3c1d540 | 57 | { |
miguelmstein | 1:1f5dc3c1d540 | 58 | maxSingle(1,0); //columna 1 |
miguelmstein | 1:1f5dc3c1d540 | 59 | maxSingle(2,0); //columna 2 |
miguelmstein | 1:1f5dc3c1d540 | 60 | maxSingle(3,0); //columna 3 |
miguelmstein | 1:1f5dc3c1d540 | 61 | maxSingle(4,0); //columna 4 |
miguelmstein | 1:1f5dc3c1d540 | 62 | maxSingle(5,0); //columna 5 |
miguelmstein | 1:1f5dc3c1d540 | 63 | maxSingle(6,0); //columna 6 |
miguelmstein | 1:1f5dc3c1d540 | 64 | maxSingle(7,0); //columna 7 |
miguelmstein | 1:1f5dc3c1d540 | 65 | maxSingle(8,0); //columna 8 |
miguelmstein | 1:1f5dc3c1d540 | 66 | |
miguelmstein | 1:1f5dc3c1d540 | 67 | } |
miguelmstein | 1:1f5dc3c1d540 | 68 | else if(t>=2001&&t<=4000) |
miguelmstein | 1:1f5dc3c1d540 | 69 | { |
miguelmstein | 1:1f5dc3c1d540 | 70 | maxSingle(1,8); //columna 1 |
miguelmstein | 1:1f5dc3c1d540 | 71 | maxSingle(2,16); //columna 2 |
miguelmstein | 1:1f5dc3c1d540 | 72 | maxSingle(3,36); //columna 3 |
miguelmstein | 1:1f5dc3c1d540 | 73 | maxSingle(4,154); //columna 4 |
miguelmstein | 1:1f5dc3c1d540 | 74 | maxSingle(5,89); //columna 5 |
miguelmstein | 1:1f5dc3c1d540 | 75 | maxSingle(6,36); //columna 6 |
miguelmstein | 1:1f5dc3c1d540 | 76 | maxSingle(7,8); //columna 7 |
miguelmstein | 1:1f5dc3c1d540 | 77 | maxSingle(8,16); //columna 8 |
miguelmstein | 1:1f5dc3c1d540 | 78 | |
miguelmstein | 1:1f5dc3c1d540 | 79 | } |
miguelmstein | 1:1f5dc3c1d540 | 80 | else if(t>=4001&&t<=6000) |
miguelmstein | 1:1f5dc3c1d540 | 81 | { |
miguelmstein | 1:1f5dc3c1d540 | 82 | maxSingle(1,0); //columna 1 |
miguelmstein | 1:1f5dc3c1d540 | 83 | maxSingle(2,0); //columna 2 |
miguelmstein | 1:1f5dc3c1d540 | 84 | maxSingle(3,0); //columna 3 |
miguelmstein | 1:1f5dc3c1d540 | 85 | maxSingle(4,0); //columna 4 |
miguelmstein | 1:1f5dc3c1d540 | 86 | maxSingle(5,0); //columna 5 |
miguelmstein | 1:1f5dc3c1d540 | 87 | maxSingle(6,0); //columna 6 |
miguelmstein | 1:1f5dc3c1d540 | 88 | maxSingle(7,0); //columna 7 |
miguelmstein | 1:1f5dc3c1d540 | 89 | maxSingle(8,0); //columna 8 |
miguelmstein | 1:1f5dc3c1d540 | 90 | |
miguelmstein | 1:1f5dc3c1d540 | 91 | } |
miguelmstein | 1:1f5dc3c1d540 | 92 | else if(t>=6001&&t<=8000) |
miguelmstein | 1:1f5dc3c1d540 | 93 | { |
miguelmstein | 1:1f5dc3c1d540 | 94 | maxSingle(1,8); //columna 1 |
miguelmstein | 1:1f5dc3c1d540 | 95 | maxSingle(2,16); //columna 2 |
miguelmstein | 1:1f5dc3c1d540 | 96 | maxSingle(3,36); //columna 3 |
miguelmstein | 1:1f5dc3c1d540 | 97 | maxSingle(4,154); //columna 4 |
miguelmstein | 1:1f5dc3c1d540 | 98 | maxSingle(5,89); //columna 5 |
miguelmstein | 1:1f5dc3c1d540 | 99 | maxSingle(6,36); //columna 6 |
miguelmstein | 1:1f5dc3c1d540 | 100 | maxSingle(7,8); //columna 7 |
miguelmstein | 1:1f5dc3c1d540 | 101 | maxSingle(8,16); //columna 8 |
miguelmstein | 1:1f5dc3c1d540 | 102 | |
miguelmstein | 1:1f5dc3c1d540 | 103 | } |
miguelmstein | 1:1f5dc3c1d540 | 104 | else if(t>=8001&&t<=10000) |
miguelmstein | 1:1f5dc3c1d540 | 105 | { |
miguelmstein | 1:1f5dc3c1d540 | 106 | maxSingle(1,0); //columna 1 |
miguelmstein | 1:1f5dc3c1d540 | 107 | maxSingle(2,0); //columna 2 |
miguelmstein | 1:1f5dc3c1d540 | 108 | maxSingle(3,0); //columna 3 |
miguelmstein | 1:1f5dc3c1d540 | 109 | maxSingle(4,0); //columna 4 |
miguelmstein | 1:1f5dc3c1d540 | 110 | maxSingle(5,0); //columna 5 |
miguelmstein | 1:1f5dc3c1d540 | 111 | maxSingle(6,0); //columna 6 |
miguelmstein | 1:1f5dc3c1d540 | 112 | maxSingle(7,0); //columna 7 |
miguelmstein | 1:1f5dc3c1d540 | 113 | maxSingle(8,0); //columna 8 |
miguelmstein | 1:1f5dc3c1d540 | 114 | |
miguelmstein | 1:1f5dc3c1d540 | 115 | } |
miguelmstein | 1:1f5dc3c1d540 | 116 | else if(t>=10001&&t<=12000) |
miguelmstein | 1:1f5dc3c1d540 | 117 | { |
miguelmstein | 1:1f5dc3c1d540 | 118 | maxSingle(1,8); //columna 1 |
miguelmstein | 1:1f5dc3c1d540 | 119 | maxSingle(2,16); //columna 2 |
miguelmstein | 1:1f5dc3c1d540 | 120 | maxSingle(3,36); //columna 3 |
miguelmstein | 1:1f5dc3c1d540 | 121 | maxSingle(4,154); //columna 4 |
miguelmstein | 1:1f5dc3c1d540 | 122 | maxSingle(5,89); //columna 5 |
miguelmstein | 1:1f5dc3c1d540 | 123 | maxSingle(6,36); //columna 6 |
miguelmstein | 1:1f5dc3c1d540 | 124 | maxSingle(7,8); //columna 7 |
miguelmstein | 1:1f5dc3c1d540 | 125 | maxSingle(8,16); //columna 8 |
miguelmstein | 1:1f5dc3c1d540 | 126 | |
miguelmstein | 1:1f5dc3c1d540 | 127 | } |
miguelmstein | 1:1f5dc3c1d540 | 128 | else if(t>=12001&&t<=16000) |
miguelmstein | 1:1f5dc3c1d540 | 129 | { |
miguelmstein | 1:1f5dc3c1d540 | 130 | maxSingle(1,255); //columna 1 |
miguelmstein | 1:1f5dc3c1d540 | 131 | maxSingle(2,255); //columna 2 |
miguelmstein | 1:1f5dc3c1d540 | 132 | maxSingle(3,255); //columna 3 |
miguelmstein | 1:1f5dc3c1d540 | 133 | maxSingle(4,255); //columna 4 |
miguelmstein | 1:1f5dc3c1d540 | 134 | maxSingle(5,255); //columna 5 |
miguelmstein | 1:1f5dc3c1d540 | 135 | maxSingle(6,255); //columna 6 |
miguelmstein | 1:1f5dc3c1d540 | 136 | maxSingle(7,255); //columna 7 |
miguelmstein | 1:1f5dc3c1d540 | 137 | maxSingle(8,255); //columna 8 |
miguelmstein | 1:1f5dc3c1d540 | 138 | } |
miguelmstein | 1:1f5dc3c1d540 | 139 | |
miguelmstein | 1:1f5dc3c1d540 | 140 | else |
miguelmstein | 1:1f5dc3c1d540 | 141 | { |
miguelmstein | 1:1f5dc3c1d540 | 142 | } |
miguelmstein | 1:1f5dc3c1d540 | 143 | t=t+1; |
miguelmstein | 1:1f5dc3c1d540 | 144 | if(t>=16000) |
miguelmstein | 1:1f5dc3c1d540 | 145 | t=0; |
miguelmstein | 1:1f5dc3c1d540 | 146 | else{} |
miguelmstein | 1:1f5dc3c1d540 | 147 | } |
miguelmstein | 1:1f5dc3c1d540 | 148 | } |