Simulink Raspberry Pi - SPI Master Transfer/Read Block Receiving Bits Shifting Problem
3 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
I am using a Raspberry Pi Model 3-B to get some sensor readings from an Arduino slave (follower) using the "Master Transfer" block. (sample time= 0.005 s)
I am trying to read two "int16" integers from the Arduino. So as an input I send 2 dummy int16 type values. (I don't need to use them in the Arduino side so they are irrelevant)
In my slave (follower) code I am writing 4 SPDR (SPI Register) commands in an interrupt routine. (Because an SPDR command writes 1 byte and I need 4 bytes for two "int16" types)
The problem is: Let's say my SPDR commands are writing "a", "b", "c" and "d" (any number between 0 and 256) steadily. So my first "int16" read should be a_b and second would be c_d.
But at every sample the readings shifts! What I mean is: first "int16" reading becomes b_c, second becomes d_a then in the next sample c_d for the first and a_b for the second... and so on.
I can't get a steady reading even without changing anything in the slave side. I make slave send the same values for to test the system and it does not work...
Any ideas what is causing this? I have tried changing MSB/LSB setting, SPI bus speed frequency and other things in target hardware resources. Btw I am using I2C with no problems at all, but I need to switch to SPI to make room for other I2C periphrals for Arduino. When Raspberry is the master in I2C lines, I can't read other I2C devices with Arduino.
Thanks in advance.
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Raspberry Pi Hardware についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!