Uno to Mega SPI resulting in varying responses

Apologies for the long post, I will try to be thorough.

Context/Background/Real Goal:
I’m building a Star Trek TNG warp core and I’m attempting to have an arduino flash rings of LEDs at various speeds with a snippet of audio track timed with the pulses.

Current Setup:
Current setup is an Arduino Uno set as an SPI master to both an MP3 Music Maker shield as well as an Arduino Mega 2560.

Music Maker Info

Arduino Uno Pins:
3 → Music Maker Pin 3
4 → Music Maker Pin 4
5 → Music Maker Pin 5
6 → Music Maker Pin 6
7 → Music Maker Pin 7
8 → Mega Pin 53
11 → Music Maker Pin 11
12 → Music Maker Pin 12
13 → Music Maker Pin 13
ICSP Header → Mega ICSP Header
GND → Music Maker GND
5V → Music Maker 5V

Reasons I’m at this point:
I’m using 610 NeoPixel LEDs for the light rings which necessitates a MEGA for the RAM. When driving both the Music Maker and the LEDs from the MEGA however, I always ended up with some type of delay between the lights and audio since the lights had to be nested within the audio or vice versa.

I tried I2C between the Uno and Mega to allow simultaneous processing but there was again a delay whenever the master changed speed that would throw off the slave.

This led me to SPI as a much faster alternative, however the Music Maker shield already uses SPI so the UNO has to be set as a master. This means I have to set the Mega as a slave and brings us to my current problem.

Current problem:
When the Master Uno sends a value of 1 to the slave, the slave receives and returns a value of 3 when it should just be returning the same value back. Similarly when the Master Uno sends a value of 2 to the slave, the slave receives and returns a value of 5. The returned value also fluctuates from 0 to 6 with no evident pattern.

By increasing the delay after the SPI transfer from 10 to 40 the slave returns the correct value ~80% of the time but still fluctuates.

When looking at the bytes themselves it appears that the sent bit is being moved left one space and the right-most bit is being flipped. I can’t figure out why though.

Send: 00000010
Receive: 00000101

Send: 00000001
Receive: 00000011

My entire code is attached since perhaps something unexpected in my spaghetti code is causing this and it was too long to post. I’m flailing about in the dark here a bit and I appreciate any help. My google-fu has failed.

Master: WarpAudioTxDuinoV3
Slave: WarpLightRxDuinoV01

Thanks!

WarpLightRxDuinoV01.ino (19.3 KB)

WarpAudioTxDuinoV3.ino (7.17 KB)

I'm using 610 NeoPixel LEDs for the light rings which necessitates a MEGA for the RAM

Unless you can procedurally generate the light information in which case RAM won't be an issue (might be tricky, but if you are just doing the same colour, or a "chaser" effect it might be possible).

  Serial.begin(9600);

Your debugging prints at this rather slow speed aren't helping.

Unless you can procedurally generate the light information

I'm not sure I know how to do that. Is there a guide you could point me to? Would that still permit me to vary individual sets to different colors? I'd like to be able to alternate ring colors for some future plans.

Your debugging prints at this rather slow speed aren't helping.

I've updated the serial print to 250000 baud but the problem doesn't seem to get better.

When viewing the Master serial monitor it shows send/receive as below with the receive fluctuating between 1 and 6 but with varying levels of repeat e.g. 1,1,3,1,6,3,3,3,3,3,1,6,etc

warpFactor sent: 1 Slave returned: 1.

warpFactor sent: 1 Slave returned: 3.

warpFactor sent: 1 Slave returned: 6.

When veiwing the Slave serial monitor it shows

warpFactor:3

consistently but just when I think it's steady it will fluctuate to

warpFactor:1

intermittently.