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.
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)