-1

此错误显示在我的串行监视器中,请参阅下面的 ESP32 代码,请帮助我解决

GURU冥想错误:Core 1 Panic'Ed(缓存禁用但缓存的存储器区域访问)核心1寄存器:PC:0x400D1580 PS:0x00060034 A0:0X400847FC A1:0X3FFBE7B0 A2:0X3FFBE7B0 A2:0x00000001 A3:0x00000001 A3:0x000000000000000000000000 x4800 x0000ffc A7 : 0x00000001 A8 : 0x80081348 A9 : 0x3ff5f024 A10 : 0x3ffbebfc A11 : 0x20000000 A12 : 0x00000400 A13 : 0x3ffb1b10 A14 : 0x00000026 A15 : 0x3ffc4598 SAR : 0x00000020 EXCCAUSE: 0x00000007 EXCVADDR: 0x00000000 LBEG : 0x40001609 LEND : 0x4000160d LCOUNT : 0x00000000 Core 1 was running in ISR 上下文:EPC1:0x40087157 EPC2:0x00000000 EPC3:0x00000000 EPC4:0x400d1580

Backtrace: 0x400d1580:0x3ffbe7b0 0x400847f9:0x3ffbe7d0 0x40087154:0x3ffb1b50 0x400e2aa9:0x3ffb1bc0 0x400e1379:0x3ffb1be0 0x400e17c7:0x3ffb1c00 0x400e015d:0x3ffb1c70 0x400e0c5f:0x3ffb1cc0 0x400df715:0x3ffb1d20 0x400dfc8d:0x3ffb1d60 0x4012d7e6:0x3ffb1d80 0x4012d9da:0x3ffb1dd0 0x4012da2d:0x3ffb1e00 0x400e2f57:0x3ffb1e20 0x400e30aa:0x3ffb1e40 0x400d70dd:0x3ffb1e60 0x400d2da9:0x3ffb1e80 0x400d1392:0x3ffb1f80 0x400d468b:0x3ffb1fb0 0x40088c05:0x3ffb1fd0

#include <esp_now.h>
#include <WiFi.h>
#include <IRremote.h>
int IR_Recv = 4; 
#define CHANNEL 3

#define NUM_SLAVES 20                   // ESP-Now can handle a maximum of 20 slaves
#define PRINTSCANRESULTS 0

IRrecv irrecv(IR_Recv);
decode_results results;
 
int slaveCount = 0;                     // Keeps count of no. of slaves with the defined prefix
esp_now_peer_info_t slaves[NUM_SLAVES]; // Stores the information of each of the slave that is added as a peer

void initESPNow();
void manageSlaves();
void scanForSlaves();
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);
void onDataRecv(const uint8_t *mac_add, const uint8_t *data, int data_len);
void sendData(uint8_t data);

void setup()
{
  Serial.begin(115200);
  irrecv.enableIRIn(); 
  WiFi.mode(WIFI_MODE_STA);  
 initESPNow();
  esp_now_register_send_cb(onDataSent);
  esp_now_register_recv_cb(onDataRecv);
 
  scanForSlaves();
  manageSlaves();
}


void loop()
{
  //Serial.println("Digital Read: " + String(digitalRead(IR_PIN)));
  
  if(slaveCount > 0)
  {
    if (irrecv.decode(&results)){
    long int decCode = results.value;
    Serial.println(results.value);
    switch (results.value){
      case 2921: //when you press the 1 button
        sendData(0);
        break;   
      case 873: //when you press the 4 button
        sendData(512);   
        break;
       case 874: //when you press the 2 button
       sendData(100);
        break;           
       case 2922: //when you press the 5 button
        sendData(300);
        break;
       default:
        Serial.println('nothing to send');
        break;       
      }
    irrecv.resume(); // Receives the next value from the button you press
    
  }   
  
}
delay(3000);
}
// Init ESP Now with fallback
void initESPNow()
{
  WiFi.disconnect();
  if (esp_now_init() == ESP_OK)
  {
    Serial.println("ESPNow Init Success");
  }
  else
  {
    Serial.println("ESPNow Init Failed");
    ESP.restart();
  }
}

// Scan for slaves in AP mode
void scanForSlaves()
{
  int8_t scanResults = WiFi.scanNetworks();
  
  //reset slaves
  memset(slaves, 0, sizeof(slaves));
  slaveCount = 0;
  Serial.println("");
  
  if (scanResults == 0)
  {
    Serial.println("No WiFi devices in AP Mode found");
  } 
  else
  {
    Serial.print("Found ");
    Serial.print(scanResults);
    Serial.println(" devices ");
    
    for (int i = 0; i < scanResults; i++)
    {
      // Print SSID and RSSI for each device found
      String SSID = WiFi.SSID(i);
      int32_t RSSI = WiFi.RSSI(i);
      String BSSIDstr = WiFi.BSSIDstr(i);

      if (PRINTSCANRESULTS)
      {
        Serial.print(i + 1);
        Serial.print(": ");
        Serial.print(SSID);
        Serial.print(" [");
        Serial.print(BSSIDstr);
        Serial.print("]");
        Serial.print(" (");
        Serial.print(RSSI);
        Serial.print(")"); 
        Serial.println("");
      }
      
      delay(10);
      
      // Check if the current device starts with `Slave`
      if (SSID.indexOf("Slave") == 0)
      {
        // SSID of interest
        Serial.print(i + 1); 
        Serial.print(": ");
        Serial.print(SSID);
        Serial.print(" [");
        Serial.print(BSSIDstr);
        Serial.print("]");
        Serial.print(" (");
        Serial.print(RSSI);
        Serial.print(")");
        Serial.println("");
        
        // Get BSSID => Mac Address of the Slave
        int mac[6];

        if(6 == sscanf(BSSIDstr.c_str(), "%x:%x:%x:%x:%x:%x%c",  &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]))
        {
          for(int j = 0; j < 6; j++)
          {
            slaves[slaveCount].peer_addr[j] = (uint8_t)mac[j];
          }
        }
        
        slaves[slaveCount].channel = CHANNEL; // pick a channel
        slaves[slaveCount].encrypt = 0; // no encryption
        slaveCount++;
      }
    }
  }

  if(slaveCount > 0)
  {
    Serial.print(slaveCount); Serial.println(" Slave(s) found, processing..");
  }
  else
  {
    Serial.println("No Slave Found, trying again.");
  }

  // clean up ram
  WiFi.scanDelete();
}

// Check if the slave is already paired with the master.
// If not, pair the slave with master
void manageSlaves()
{
  if(slaveCount > 0)
  {
    for(int i = 0; i < slaveCount; i++)
    {
      const esp_now_peer_info_t *peer = &slaves[i];
      const uint8_t *peer_addr = slaves[i].peer_addr;
      Serial.print("Processing: ");
      
      for(int j = 0; j < 6; j++)
      {
        Serial.print((uint8_t) slaves[i].peer_addr[j], HEX);
        if (j != 5)
        {
          Serial.print(":");
        }
      }
      
      Serial.print(" Status: ");
      
      // check if the peer exists
      bool exists = esp_now_is_peer_exist(peer_addr);
      if(exists)
      {
        // Slave already paired.
        Serial.println("Already Paired");
      }
      else
      {
        // Slave not paired, attempt pair
        esp_err_t addStatus = esp_now_add_peer(peer);
        if(addStatus == ESP_OK)
        {
          // Pair success
          Serial.println("Pair success");
        }
        else if (addStatus == ESP_ERR_ESPNOW_NOT_INIT)
        {
          // How did we get so far!!
          Serial.println("ESPNOW Not Init");
        }
        else if (addStatus == ESP_ERR_ESPNOW_ARG)
        {
          Serial.println("Add Peer - Invalid Argument");
        }
        else if (addStatus == ESP_ERR_ESPNOW_FULL)
        {
          Serial.println("Peer list full");
        }
        else if (addStatus == ESP_ERR_ESPNOW_NO_MEM)
        {
          Serial.println("Out of memory");
        }
        else if (addStatus == ESP_ERR_ESPNOW_EXIST)
        {
          Serial.println("Peer Exists");
        }
        else
        {
          Serial.println("Not sure what happened");
        }
        delay(1000);
      }
    }
  }
  else
  {
    // No slave found to process
    Serial.println("No Slave found to process");
  }
}

// send data
void sendData(uint8_t data)
{
  for(int i = 0; i < slaveCount; i++)
  {
    const uint8_t *peer_addr = slaves[i].peer_addr;
    if (i == 0)
    {
      // print only for first slave
      Serial.print("Sending: ");
      Serial.println(data);
    }
    
    esp_err_t result = esp_now_send(peer_addr, &data, sizeof(data));
    Serial.print("Send Status: ");
    
    if (result == ESP_OK) {
      Serial.println("Success");
    } else if (result == ESP_ERR_ESPNOW_NOT_INIT) {
      // How did we get so far!!
      Serial.println("ESPNOW not Init.");
    } else if (result == ESP_ERR_ESPNOW_ARG) {
      Serial.println("Invalid Argument");
    } else if (result == ESP_ERR_ESPNOW_INTERNAL) {
      Serial.println("Internal Error");
    } else if (result == ESP_ERR_ESPNOW_NO_MEM) {
      Serial.println("ESP_ERR_ESPNOW_NO_MEM");
    } else if (result == ESP_ERR_ESPNOW_NOT_FOUND) {
      Serial.println("Peer not found.");
    } else {
      Serial.println("Not sure what happened");
    }
    delay(100);
  }
}

// callback when data is sent from Master to Slave
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
{
  char macStr[18];
 // sendTime = millis();
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
           
  Serial.print("Last Packet Sent to: ");
  Serial.println(macStr);
  Serial.print("Last Packet Send Status: ");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}

// callback when data is received from Slave to Master
void onDataRecv(const uint8_t *mac_add, const uint8_t *data, int data_len)
{
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_add[0], mac_add[1], mac_add[2], mac_add[3], mac_add[4], mac_add[5]);
           
  Serial.print("Last Packet Recv from: ");
  Serial.println(macStr);
  Serial.print("Last Packet Recv Data: ");
  Serial.println(*data);
  Serial.println("");
}```
4

1 回答 1

2

出于好奇,我尝试了您的代码,并且可以重现您所面临的情况。但我注意到,如果我irrecv.enableIRIn();WiFi.mode(WIFI_MODE_STA);in换行setup(),崩溃就会停止。

这将导致草图崩溃

#include <WiFi.h>
#include <IRremote.h>

int IR_Recv = 4; 

IRrecv irRecv(IR_Recv);
decode_results results;

void setup()
{
  Serial.begin(115200);
  irRecv.enableIRIn();
  WiFi.mode(WIFI_MODE_STA); 
  
}


void loop() {
}

这将完美地工作而不会崩溃

#include <WiFi.h>
#include <IRremote.h>

int IR_Recv = 4; 

IRrecv irRecv(IR_Recv);
decode_results results;

void setup()
{
  Serial.begin(115200);
  WiFi.mode(WIFI_MODE_STA);
  irRecv.enableIRIn();   
}


void loop() {
}

我无法解释为什么,什么irrecv.enableIRIn()是设置中断并重置 timer2,但我看不出这如何影响WiFi.mode(WIFI_MODE_STA),也许其他人可以解释为什么会发生这种情况。

于 2020-07-25T07:25:07.963 回答