Reputation: 1
I am trying to change the state of some motors using a PN532 sensor, I want that those motors vibrate with a determinate frequency so I am using a timer. Those motors turn off when contador=20 or when I press a bottom but when the motors turn off, I got a message error. How can I solve it? This is my code.
#include <Wire.h>
#include <SPI.h> //Librería para comunicación SPI serial parallel interface
#include <UNIT_PN532.h> //Librería Modificada ya que la tasa de bits que viene predefinida
//en la librería de Adafruit es demasiado rápida para el ESP32 por lo cual se debe modificar este dato para poder utilizarlo con esta placa
//Conexiones SPI del ESP32
#define PN532_SCK (18)
#define PN532_MOSI (23)
#define PN532_SS (5)
#define PN532_MISO (19)
#define motor1 (33)
#define motor2 (32)
#define motor3 (25)
#define motor4 (26)
#define boton1 (2)
void IRAM_ATTR onTimer();
void isr_boton();
uint8_t DatoRecibido[4]; //Para almacenar los datos
int contador=0;
int boton_restart=0;
UNIT_PN532 nfc(PN532_SS);// Línea enfocada para la comunicación por SPI
hw_timer_t * timer = NULL;
void setup() {
Serial.begin(115200); //Inicio de puerto Serial a 115200 baudios
nfc.begin(); //Comienza la comunicación del PN532
uint32_t versiondata = nfc.getFirmwareVersion();//Obtiene información de la placa
if (! versiondata) { //Si no se encuentra comunicación con la placa --->
Serial.print("No se encontró la placa PN53x");
while (1); // Detener
}
//Establezca el número máximo de reintentos para leer de una tarjeta.
//Esto evita que tengamos que esperar eternamente por una tarjeta,
//que es el comportamiento predeterminado del PN532.
nfc.setPassiveActivationRetries(0xFF);
nfc.SAMConfig(); //Configura la placa para realizar la lectura
// Serial.println("Esperando una tarjeta ISO14443A ...");
pinMode(motor1, OUTPUT); // Se configuran los pines como salidas
pinMode(motor2, OUTPUT);
pinMode(motor3, OUTPUT);
pinMode(motor4, OUTPUT);
pinMode(boton1, INPUT_PULLDOWN);
attachInterrupt(boton1,isr_boton,RISING);
}
void loop() {
boolean LeeTarjeta;//Variable para almacenar la detección de una tarjeta
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Búfer para almacenar el UID devuelto
uint8_t LongitudUID; //Variable para almacenar la longitud del UID de la tarjeta
//Recepción y detección de los datos de la tarjeta y almacenamiento en la variable "LeeTarjeta"
LeeTarjeta = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &LongitudUID);
Serial.println("loop");
//Se detecto un tarjeta RFID
if (LeeTarjeta) {
timer = timerBegin(0, 80, true); // timer 0, MWDT clock periodo = 12.5 ns * TIMGn_Tx_WDT_CLK_PRESCALE -> 12.5 ns * 80 -> 1000 ns = 1 us, countUp--> conteo ascendente
timerAttachInterrupt(timer, &onTimer, true); // edge (not level) triggered
timerAlarmWrite(timer, 1000000, true); // 1000000 * 1 us = 1 s, autoreload true
timerAlarmEnable(timer); // enable
}
//Si no se detecta tarjeta
else
{
Serial.print(PN532_SCK);
Serial.println("Se agotó el tiempo de espera de una tarjeta");
}
vTaskDelay(portMAX_DELAY); // wait as much as posible ...
}
void IRAM_ATTR onTimer(){ // interrupción del timer cuando se c
digitalWrite(motor1,!digitalRead(motor1)); // cambio de estado de los leds
digitalWrite(motor2,!digitalRead(motor2));
digitalWrite(motor3,!digitalRead(motor3));
digitalWrite(motor4,!digitalRead(motor4));
contador++;
//Serial.print(contador);
if (contador==20||boton_restart==1){
digitalWrite(motor1,LOW); // cambio de estado de los leds
digitalWrite(motor2,LOW);
digitalWrite(motor3,LOW);
digitalWrite(motor4,LOW);
contador=0;
timerDetachInterrupt(timer);
nfc.startPassiveTargetIDDetection(PN532_MIFARE_ISO14443A);
Serial.print("fin");
//ESP.restart();
}
}
void isr_boton(){
boton_restart=1;
}
and the complete message error
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400849c6 PS : 0x00050831 A0 : 0x800d14cb A1 : 0x3ffbf0a0
A2 : 0x00000044 A3 : 0x00018044 A4 : 0x000637ff A5 : 0x3ffbf080
A6 : 0x000000ff A7 : 0x00000001 A8 : 0x000000ff A9 : 0x40089550
A10 : 0x00000003 A11 : 0x00060c23 A12 : 0x80081abc A13 : 0x3ffbf060
A14 : 0x3ffbff40 A15 : 0x00000000 SAR : 0x0000001b EXCCAUSE: 0x0000001c
EXCVADDR: 0x800d14d7 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffe
Core 1 was running in ISR context:
EPC1 : 0x400849c6 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x40083833
ELF file SHA256: 0000000000000000
Backtrace: 0x400849c6:0x3ffbf0a0 0x400d14c8:0x3ffbc6b0 0x400e1d5b:0x3ffbc6d0 0x400885ee:0x3ffbc6f0 0x40086e9d:0x3ffbc710
Rebooting...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
I think the error is using nfc.startPassiveTargetIDDetection(PN532_MIFARE_ISO14443A) but I am not sure.
Upvotes: 0
Views: 313
Reputation: 9
In case you use IDE 2.x, java tools don't work any more.
Try using a different tool like https://github.com/holgerlembke/ESPEDfGK
Upvotes: 0