I'm sending a U8 bit integer from LabView SPI program to my Arduino Mega 2560 (which is supposed to be acting as the slave.) In my ISR function, I grab the byte from the SPDR register and store it in a buffer array (to be processed and printed to my Serial console.)
In Labview, I literally just copied the following setup, situation by situation (except I added a 'reverse 1D array' so that, hopefully, the MSB is in the 0th element of the array. This setup passes SPI data in an 8-iteration loop so that all bits get sent.
most significant bit, according to Labview....without the array reversal, the 0th element would contain the least significant bit. Although, all in all, I don't believe that reversing the array is necessary anyway...the results would still be noticeable.
And good call, I switched it to volatile, however the results were the same.
without the array reversal, the 0th element would contain the least significant bit.
I don't understand what you mean by "array reversal". You store an 8 bit value in the array - whether in the first element or the second isn't really clear. You read the first element in the array. You never, that I can see, reverse the bits in any element in the array.
Storing an element in an array doesn't, fortunately, reverse bits automatically.
Input - 6
initial array[8] - 00000110, where the two 1's are the 5th and 6th elements.
reverse array - 01100000, then the MOSI line transfers the data.
Problem is, when I read that entire byte from the SPDR register, I get the jargon I posted above. I should be able to read the byte, whether it as 00000110 or 01100000 and get a solid number in the first element position for my volatile char buff[] array.
Turns out the issue was my method for sending data on the MOSI line...the button I used was not being properly shut off at the end of the transaction so the register kept piling up random data (which had the Arduino interrupt function capture each data bit...or so I believe at least.)
I do have a follow up question in terms of syncing clock signals. My master runs at 40MHz and, from what I've read, the Arduino runs at 16MHz. I configured the 8-bit data to be sent with 2us pulses at 50% duty cycles. This was too fast for the Arduino, so how do I match up these differing clocks?