You forgot to use #include <SPI.h> in your arduino code. So the code compiled for I2C interface.

Beware using the wrong pins for external SPI deviceon your M5Stack. You may brick your display. Interfacing to an external a SPI peripheral device you should use pins which are not in conflict with the pins used for M5Stack internals, as I already wrote in my comments on SPI Interfacing a few days ago:
You should keep it as they are saying on my spec sheet for the Heltec ESP32 LoRa board: "Pins used by on board OLED or LoRA must not be used for other purpose unless you know what you are doing !
Accordingly, on the M5Stack you should only use the pins marked in blue.