From 31d5ec18d6a9b02d69efc437d97effc44eb8690a Mon Sep 17 00:00:00 2001 From: Angelo Date: Wed, 8 Mar 2017 19:27:55 +0800 Subject: [PATCH] Fix compatible problem on nodeMCU (ESP8266) add delay(0) to reset the soft wdt --- DFRobotDFPlayerMini.cpp | 7 +++++-- examples/GetStarted/getStarted.ino | 10 ++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/DFRobotDFPlayerMini.cpp b/DFRobotDFPlayerMini.cpp index 207be38..c58da12 100644 --- a/DFRobotDFPlayerMini.cpp +++ b/DFRobotDFPlayerMini.cpp @@ -33,6 +33,7 @@ uint16_t DFRobotDFPlayerMini::calculateCheckSum(uint8_t *buffer){ void DFRobotDFPlayerMini::sendStack(){ if (_sending[Stack_ACK]) { while (_isSending) { + delay(0); available(); } } @@ -81,7 +82,9 @@ void DFRobotDFPlayerMini::disableACK(){ bool DFRobotDFPlayerMini::waitAvailable(){ _isSending = true; - while (!available()); + while (!available()){ + delay(0); + } return _handleType != TimeOut; } @@ -195,6 +198,7 @@ bool DFRobotDFPlayerMini::validateStack(){ bool DFRobotDFPlayerMini::available(){ while (_serial->available()) { + delay(0); if (_receivedIndex == 0) { _received[Stack_Header] = _serial->read(); #ifdef _DEBUG @@ -394,7 +398,6 @@ int DFRobotDFPlayerMini::readVolume(){ uint8_t DFRobotDFPlayerMini::readEQ(){ sendStack(0x44); - while (!available()); if (waitAvailable()) { return read(); } diff --git a/examples/GetStarted/getStarted.ino b/examples/GetStarted/getStarted.ino index 19c6197..7f70693 100644 --- a/examples/GetStarted/getStarted.ino +++ b/examples/GetStarted/getStarted.ino @@ -1,11 +1,11 @@ /*************************************************** DFPlayer - A Mini MP3 Player For Arduino - + *************************************************** This example shows the basic function of library for DFPlayer. - Created 2016-12-07 + Created 2014-8-28 By [Angelo qiao](Angelo.qiao@dfrobot.com) GNU Lesser General Public License. @@ -15,7 +15,7 @@ DFPlayer - A Mini MP3 Player For Arduino /***********Notice and Trouble shooting*************** 1.Connection and Diagram can be found here - + <> 2.This code is tested on Arduino Uno, Leonardo, Mega boards. ****************************************************/ @@ -40,7 +40,9 @@ void setup() Serial.println(F("Unable to begin:")); Serial.println(F("1.Please recheck the connection!")); Serial.println(F("2.Please insert the SD card!")); - while(true); + while(true){ + delay(0); // Code to compatible with ESP8266 watch dog. + } } Serial.println(F("DFPlayer Mini online."));