ESP32 crashing connected to ESPHome and CAN bus

I have an ESP32 connected to an integrated MCP2515 module (with TJA1050 Receiver) which is then connected to a CAN bus. For software I am using the ESPHome CANBus component.

The problem is after receiving approx 40 to 50 CAN Frames (8 bytes each) the ESP goes offline. The power is still on but I get this error msg: WARNING 192.168.1.50: Connection error occurred: [Errno 104] Connection reset by peer

INFO Processing unexpected disconnect from ESPHome API for 192.168.1.50

WARNING Disconnected from API

WARNING Can’t connect to ESPHome API for 192.168.1.50: Error connecting to (‘192.168.1.50’, 6053): [Errno 111] Connect call failed (‘192.168.1.50’, 6053) (SocketAPIError)

And the only way I can get it back online is to disconnect the CAN bus and recycle the power to the ESP32 and MCP2515. Then it does the same again. Receives 40+ frames and crashes.

The data received before it goes offline is fine. But something is crashing and I cannot figure out what.

I have tried connecting to 2 totally different CAN Bus networks with the same problem.

I power my ESP32 and the MCP2515 separately with a 5V power module.

These are the PIN assignments:

MCP2515 - ESP32

SCK - P18

SI - P23

SO - P19

CS - P5

GND - GND

VCC - 5V

spi:
  id: spi_bus
  clk_pin: GPIO18
  miso_pin: GPIO19
  mosi_pin: GPIO23
  
canbus:
  - platform: mcp2515
    cs_pin: GPIO5
    spi_id: spi_bus
    can_id: 0
    use_extended_id: True
    bit_rate: 250kbps
    on_frame:
    - can_id: 0
      use_extended_id: True
      can_id_mask: 0  
      then:
      - lambda: |- 

          ESP_LOGD("can_id", "Received CAN message with ID: %x", can_id);

          for (int i = 0; i < 8; i++) {
              ESP_LOGD("can_data", "Byte %d: %02x", i, x[i]);
          }
       
          ESP_LOGD("can_id", "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

Any suggestions?