浏览代码

Resolve corruption of Max7219 Debug LED Matrix

Roxy-3D 7 年前
父节点
当前提交
26cc12eaa4
共有 1 个文件被更改,包括 21 次插入9 次删除
  1. 21
    9
      Marlin/src/feature/Max7219_Debug_LEDs.cpp

+ 21
- 9
Marlin/src/feature/Max7219_Debug_LEDs.cpp 查看文件

64
 static uint8_t LEDs[8] = { 0 };
64
 static uint8_t LEDs[8] = { 0 };
65
 
65
 
66
 #ifdef CPU_32_BIT
66
 #ifdef CPU_32_BIT
67
-  #define MS_DELAY() delayMicroseconds(5)  // 32-bit processors need a delay to stabilize the signal
67
+  #define MS_DELAY() delayMicroseconds(7)  // 32-bit processors need a delay to stabilize the signal
68
 #else
68
 #else
69
-  #define MS_DELAY() NOOP
69
+  #define MS_DELAY() DELAY_3_NOP
70
 #endif
70
 #endif
71
 
71
 
72
 void Max7219_PutByte(uint8_t data) {
72
 void Max7219_PutByte(uint8_t data) {
214
   Max7219(8 - col, LEDs[col]);
214
   Max7219(8 - col, LEDs[col]);
215
 }
215
 }
216
 
216
 
217
+void Max7219_register_setup() {
218
+  //initiation of the max 7219
219
+  Max7219(max7219_reg_scanLimit, 0x07);
220
+  Max7219(max7219_reg_decodeMode, 0x00);       // using an led matrix (not digits)
221
+  Max7219(max7219_reg_shutdown, 0x01);         // not in shutdown mode
222
+  Max7219(max7219_reg_displayTest, 0x00);      // no display test
223
+  Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
224
+                                               // range: 0x00 to 0x0F
225
+}
226
+
217
 void Max7219_init() {
227
 void Max7219_init() {
218
   uint8_t i, x, y;
228
   uint8_t i, x, y;
219
 
229
 
223
   OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
233
   OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
224
   delay(1);
234
   delay(1);
225
 
235
 
226
-  //initiation of the max 7219
227
-  Max7219(max7219_reg_scanLimit, 0x07);
228
-  Max7219(max7219_reg_decodeMode, 0x00);  // using an led matrix (not digits)
229
-  Max7219(max7219_reg_shutdown, 0x01);    // not in shutdown mode
230
-  Max7219(max7219_reg_displayTest, 0x00); // no display test
231
-  Max7219(max7219_reg_intensity, 0x01 & 0x0F); // the first 0x0F is the value you can set
232
-                                               // range: 0x00 to 0x0F
236
+  Max7219_register_setup();
237
+
233
   for (i = 0; i <= 7; i++) {      // empty registers, turn all LEDs off
238
   for (i = 0; i <= 7; i++) {      // empty registers, turn all LEDs off
234
     LEDs[i] = 0x00;
239
     LEDs[i] = 0x00;
235
     Max7219(i + 1, 0);
240
     Max7219(i + 1, 0);
282
     #endif
287
     #endif
283
     CRITICAL_SECTION_END
288
     CRITICAL_SECTION_END
284
   #endif
289
   #endif
290
+      
291
+  static uint16_t refresh_cnt = 0;  // The Max7219 circuit boards available for several dollars on eBay 
292
+  if (refresh_cnt++ > 50000) {      // are vulnerable to electrical noise, especially with long wires
293
+    Max7219_register_setup();       // next to high current wires. If the display becomes corrupted due
294
+    Max7219_LED_Toggle(7, 0);       // to electrical noise, this will fix it within a couple of seconds.
295
+    refresh_cnt = 0;
296
+  }
285
 
297
 
286
   #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
298
   #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
287
     static millis_t next_blink = 0;
299
     static millis_t next_blink = 0;

正在加载...
取消
保存