用户工具

站点工具


knowledge:3d_print:2022102301

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
knowledge:3d_print:2022102301 [2022/10/23 12:01] 弘毅knowledge:3d_print:2022102301 [2023/06/14 12:34] (当前版本) 弘毅
行 6: 行 6:
 static void xflash_err_msg() static void xflash_err_msg()
 { {
- lcd_clear(); +  lcd_clear(); 
- lcd_puts_P(_n("External SPI flash\nXFLASH is not res-\nponding. Language\nswitch unavailable."));+  lcd_puts_P(_n("External SPI flash\nXFLASH is not res-\nponding. Language\nswitch unavailable."));
 } }
  
 // "Setup" function is called by the Arduino framework on startup. // "Setup" function is called by the Arduino framework on startup.
-// Before startup, the Timers-functions (PWM)/Analog RW and HardwareSerial provided by the Arduino-code +// Before startup, the Timers-functions (PWM)/Analog RW and HardwareSerial provided by the Arduino-code
 // are initialized by the main() routine provided by the Arduino framework. // are initialized by the main() routine provided by the Arduino framework.
 void setup() void setup()
 { {
- timer2_init(); // enables functional millis+  timer2_init(); // enables functional millis
  
- mmu_init();+  mmu_init();
  
- ultralcd_init();+  ultralcd_init();
  
- spi_init();+  spi_init();
  
- lcd_splash(); +  lcd_splash(); 
-    Sound_Init();                                // also guarantee "SET_OUTPUT(BEEPER)"+  Sound_Init();                                // also guarantee "SET_OUTPUT(BEEPER)"
  
- selectedSerialPort = eeprom_read_byte((uint8_t *)EEPROM_SECOND_SERIAL_ACTIVE); +  selectedSerialPort = eeprom_read_byte((uint8_t *)EEPROM_SECOND_SERIAL_ACTIVE); 
- if (selectedSerialPort == 0xFF) selectedSerialPort = 0; +  if (selectedSerialPort == 0xFF) selectedSerialPort = 0; 
- eeprom_update_byte((uint8_t *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort); +  eeprom_update_byte((uint8_t *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort); 
- MYSERIAL.begin(BAUDRATE); +  MYSERIAL.begin(BAUDRATE); 
- fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream +  fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream 
- stdout = uartout;+  stdout = uartout;
  
 #ifdef XFLASH #ifdef XFLASH
-    bool xflash_success = xflash_init(); +  bool xflash_success = xflash_init(); 
- uint8_t optiboot_status = 1; +  uint8_t optiboot_status = 1; 
- if (xflash_success) +  if (xflash_success) 
-+  
- optiboot_status = optiboot_xflash_enter();+    optiboot_status = optiboot_xflash_enter();
 #if (LANG_MODE != 0) //secondary language support #if (LANG_MODE != 0) //secondary language support
-        update_sec_lang_from_external_flash();+    update_sec_lang_from_external_flash();
 #endif //(LANG_MODE != 0) #endif //(LANG_MODE != 0)
- +  
- else +  else 
-+  
-     xflash_err_msg(); +    xflash_err_msg(); 
- }+  }
 #else #else
- const bool xflash_success = true;+  const bool xflash_success = true;
 #endif //XFLASH #endif //XFLASH
 </code> </code>
-通过查看源码,发现该错误信息是Arduino的Setup函数初始化中显示的。+通过查看源码,发现该错误信息是Arduino的Setup函数初始化中显示的。是否error是又xflash_init()函数返回的数据决定
  
 +我们在xflash.c的51行找到该函数。他初始化XFLASH_PIN_CS引脚为SPI的CS引脚,然后执行xflash_mfrid_devid()函数判断返回。
 +
 +XFLASH_PIN_CS是Arduino MEGA2560的D32引脚,也就是PC5.
 +<code>
 +int xflash_mfrid_devid(void);
 +
 +
 +int8_t xflash_init(void)
 +{
 +  _CS_HIGH();
 +  SET_OUTPUT(XFLASH_PIN_CS);
 +  XFLASH_SPI_ENTER();
 +  if (!xflash_mfrid_devid()) return 0;
 +  return 1;
 +}
 +</code>
 +
 +xflash_mfrid_devid()函数在xflash.c的193行,主要还是与Flash进行通信,获取Flash的型号。以此来确认是否通信成功。
 +<code>
 +int xflash_mfrid_devid(void)
 +{
 +  _CS_LOW();
 +  _SPI_TX(_CMD_MFRID_DEVID);           // send command 0x90
 +  uint8_t cnt = 3;                     // 3 address bytes
 +  while (cnt--)                        // send address bytes
 +    _SPI_TX(0x00);
 +  uint8_t xflash_mfrid = _SPI_RX();  // receive mfrid
 +  uint8_t xflash_devid = _SPI_RX();  // receive devid
 +  _CS_HIGH();
 +  return
 +    ((xflash_mfrid == _MFRID_W25X20CL) && (xflash_devid == _DEVID_W25X20CL)) ||
 +    ((xflash_mfrid == _MFRID_GD25Q20C) && (xflash_devid == _DEVID_GD25Q20C));
 +}
 +</code>
 +通过测试,发现该问题会有LCD2004硬件的SD卡CS到主控接触不良引起。当LCD2004的SD卡的CS到主控接触不良时,就会引起这个错误。
knowledge/3d_print/2022102301.1666526514.txt · 最后更改: 2023/06/07 04:09 (外部编辑)

Valid HTML5 Valid CSS Driven by DokuWiki