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
SPI_ Master SendByteArray only sending once in loop
-
- Posts: 8
- http://meble-kuchenne.info.pl
- Joined: Tue May 11, 2021 10:53 pm
- Has thanked: 3 times
- Been thanked: 1 time
-
- Valued Contributor
- Posts: 1313
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 317 times
- Been thanked: 458 times
Re: SPI_ Master SendByteArray only sending once in loop
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
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
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
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
-
- Valued Contributor
- Posts: 1213
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 118 times
- Been thanked: 622 times
Re: SPI_ Master SendByteArray only sending once in loop
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..
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
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..
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..