Page 1 of 1

SPI_ Master SendByteArray only sending once in loop

Posted: Tue Apr 09, 2024 10:03 pm
by Nake350
Im using FC10 and trying to send an 8 Byte Array every second using a loop, but its only sending the array contents correctly on the first loop with all following sends being zeros, i.e an empty array. What am I doing wrong?

Thank you

Re: SPI_ Master SendByteArray only sending once in loop

Posted: Tue Apr 09, 2024 10:44 pm
by LeighM
I think the array gets filled with the received in data.
But I can't check the component just now.

Re: SPI_ Master SendByteArray only sending once in loop

Posted: Wed Apr 10, 2024 4:27 am
by chipfryer27
Hi

Without seeing your chart it is difficult to guess how you are sending.

As Leigh indicates, SPI is always bidirectional (even if you have nothing to receive).

At the Master, after you fill the buffer with data to send, it "clocks" the data out and the Slave clocks this data in. At the same time as the data is being clocked in at the Slave, the contents of its buffer are being clocked out / in to the Master thereby replacing the contents.

Say the Master buffer contained "x" and the Slave "y". After transmission (instigated by the Master) the Master buffer would contain "y" and the Slave "x". If the Master receive wasn't connected it would still fill with zero's.

You need to write the value of whatever you wish to send to the buffer before it is sent.

Regards

Re: SPI_ Master SendByteArray only sending once in loop

Posted: Thu Apr 11, 2024 10:15 pm
by Nake350
Hi, and thank you both for your replys and info.
What you are saying makes sense, but as far as I can see I am sending a variable every loop, so I was expecting the send buffer will be updated my variable every loop?

My 1 second loop simply contains;

SPI MASTER 1:Enable_CS()
SPI MASTER SendByteArray(8, FIFO)
SPI MASTER 1:Disable_CS()

Regards

Re: SPI_ Master SendByteArray only sending once in loop

Posted: Fri Apr 12, 2024 6:48 am
by mnfisher
Please post your code - or a snippet showing the problem.

SPI sends overwrite the sent data with values received by the sender (or 0 if there is no reply) - so you might need to just update the array values each time..

Code: Select all

loop (forever)
       loop (i = 0.. 7)
              array[i] = val[i]
      send (array) 
      delay(1s)
      

Re: SPI_ Master SendByteArray only sending once in loop

Posted: Sun Apr 14, 2024 1:21 pm
by Nake350
Thank you for your responses.
It turns out I should have set the array as a constant.
Once set as a constant it sends to SPI every time as needed.

Best regards..