ESP32 is rebooting while running a function

Hi,
I'm using ESP32 module and It communicates Arduino mega via UART using SerialTransfer.h. But when I tried to transmit struct, ESP32 is rebooting.
The function is below.

void sendData() 
{
  uint16_t sendSize = 0;
  sendSize = myTransfer.txObj(packet, sendSize);
  myTransfer.sendData(sendSize);
}

Please help me to find the solution.

Have you tried using the ESP Exception Decoder tool in the IDE ?

1 Like

Yes It gives me
PC: 0x400d71d7: SerialTransfer::sendData(unsigned short const&, unsigned char) at C:\Users\Documents\Arduino\libraries\SerialTransfer\src\SerialTransfer.cpp line 66 EXCVADDR: 0x00000000

The line 66 shows

port->write(packet.preamble, sizeof(packet.preamble));

This is very strange for me: you are passing a variable sendSize as parameter of function txObj() and assigning the result of function to the same variable.

As my opinion the second parameter of function should be the size of packet, not the local variable uint16_t sendSize = 0;

1 Like

But SerialTransfer library says this. I did it according to that example.

void loop()
{
  // use this variable to keep track of how many
  // bytes we're stuffing in the transmit buffer
  uint16_t sendSize = 0;

  ///////////////////////////////////////// Stuff buffer with struct
  sendSize = myTransfer.txObj(testStruct, sendSize);

  ///////////////////////////////////////// Stuff buffer with array
  sendSize = myTransfer.txObj(arr, sendSize);

  ///////////////////////////////////////// Send buffer
  myTransfer.sendData(sendSize);
  delay(500);
}

and Error is like this

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x400d1cab  PS      : 0x00060230  A0      : 0x800d1b79  A1      : 0x3ffccca0
A2      : 0x3ffc3bdc  A3      : 0x00000005  A4      : 0x00000000  A5      : 0x3ffdf2dc  
A6      : 0x3ffccd40  A7      : 0x3ffdca90  A8      : 0x800d1ca3  A9      : 0x3ffccc70
A10     : 0x00000000  A11     : 0x000001fc  A12     : 0x3ffcccac  A13     : 0x00000005  
A14     : 0x3ffc3cdc  A15     : 0x3ffc3ddc  SAR     : 0x00000010  EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

ELF file SHA256: 0000000000000000

Backtrace: 0x400d1cab:0x3ffccca0 0x400d1b76:0x3ffcccd0 0x400d1c0d:0x3ffccd00 0x400d2b31:0x3ffccd40 0x400d6f35:0x3ffccff0 0x400d54b1:0x3ffcd010 0x400d58f5:0x3ffcd060 0x400d4e22:0x3ffcd080 0x400d35c5:0x3ffcd0e0 0x400f5ca9:0x3ffcd100 0x400eda4e:0x3ffcd140 0x4008ff9e:0x3ffcd170

Rebooting...

I didn't know this library, but I've seen that it use an internal buffer.
Example should be a little better explained as my opinion, because it use the same variable for 2 different purposes and this is confusing: first to allocate different objects in the tx buffer using sendSize as index (with the two txObj() instructions) and then to store the amount of bytes sent.

Anyway, if you put the complete code, I can try to debug with ESP-PROG debugger if you want in order to get exactly the line causing exception.

/*
	 uint16_t SerialTransfer::txObj(const T &val, const uint16_t &index=0, const uint16_t &len=sizeof(T))
	 Description:
	 ------------
	  * Stuffs "len" number of bytes of an arbitrary object (byte, int,
	  float, double, struct, etc...) into the transmit buffer (txBuff)
	  starting at the index as specified by the argument "index"
	 Inputs:
	 -------
	  * const T &val - Pointer to the object to be copied to the
	  transmit buffer (txBuff)
	  * const uint16_t &index - Starting index of the object within the
	  transmit buffer (txBuff)
	  * const uint16_t &len - Number of bytes of the object "val" to transmit
	 Return:
	 -------
	  * uint16_t maxIndex - uint16_t maxIndex - Index of the transmit buffer (txBuff) that directly follows the bytes processed
	  by the calling of this member function
	*/
	template <typename T>
	uint16_t txObj(const T& val, const uint16_t& index = 0, const uint16_t& len = sizeof(T))
	{
		return packet.txObj(val, index, len);
	}
1 Like