I haven't looked through your code yet my head is splitting, but if you are using a device over SPI (serial peripheral interface) that has MOSI, MISO, SCK, , SS, GND, VCC on an Arduino Mega they use different pins then an Arduino Uno.
Specifically MISO=50, MOSI=51, SCK=52 and SS=53. You can...