SPI_ Master SendByteArray only sending once in loop

Use this section to discuss your embedded Flowcode projects.
Post Reply
Nake350
Posts: 8
http://meble-kuchenne.info.pl
Joined: Tue May 11, 2021 10:53 pm
Has thanked: 3 times
Been thanked: 1 time

Flowcode v10 SPI_ Master SendByteArray only sending once in loop

Post 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

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 72 times
Been thanked: 218 times

Re: SPI_ Master SendByteArray only sending once in loop

Post by LeighM »

I think the array gets filled with the received in data.
But I can't check the component just now.

chipfryer27
Valued Contributor
Posts: 1149
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 287 times
Been thanked: 412 times

Re: SPI_ Master SendByteArray only sending once in loop

Post 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

Nake350
Posts: 8
Joined: Tue May 11, 2021 10:53 pm
Has thanked: 3 times
Been thanked: 1 time

Re: SPI_ Master SendByteArray only sending once in loop

Post 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

mnfisher
Valued Contributor
Posts: 964
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 513 times

Re: SPI_ Master SendByteArray only sending once in loop

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

Nake350
Posts: 8
Joined: Tue May 11, 2021 10:53 pm
Has thanked: 3 times
Been thanked: 1 time

Re: SPI_ Master SendByteArray only sending once in loop

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

Post Reply