SPI mode and bitrate cannot be changed in Arduino DUE

조회 수: 1 (최근 30일)
Massoud Tohidian
Massoud Tohidian 2019년 8월 6일
댓글: Massoud Tohidian 2019년 8월 13일
I'm using MATLAB R2016a with Arduino DUE. When a SPI device object is created using spidev, it cannot correctly change SPI mode and bitrate. Mode is alway 0 and bitrate is always 4Mbps. I have tried this also with R2019a and it is the same.
For example, I try to use this command to change Mode to 3 and bitrate to 1Mbps:
spidev(a,'D10','Mode',3,'Bitrate',1000000);
But it does not change anything there.
Is there a bug there? How can it be fixed?
Thanks in advance.
  댓글 수: 1
Andrey Kiselnikov
Andrey Kiselnikov 2019년 8월 6일
Before using the interfaces you should create the system object that will control the board. Can you attach your script here?

댓글을 달려면 로그인하십시오.

채택된 답변

Andrey Kiselnikov
Andrey Kiselnikov 2019년 8월 6일
Right now I have no Arduino Due, but I can check your script next week. If it will be actual, let me know please.
  댓글 수: 3
Andrey Kiselnikov
Andrey Kiselnikov 2019년 8월 12일
Hi, I remember what i promised!
>> a = arduino()
a =
arduino with properties:
Port: 'COM6'
Board: 'Due'
AvailablePins: {'D2-D53', 'A0-A11'}
AvailableDigitalPins: {'D2-D53', 'A0-A11'}
AvailablePWMPins: {'D2-D13'}
AvailableAnalogPins: {'A0-A11'}
AvailableI2CBusIDs: [0, 1]
Libraries: {'SPI'}
>> dev = spidev(a,'D10','Mode',3,'Bitrate',1000000)
Warning: Function spidev will be removed. Use device instead.Click here to turn off this warning.
dev =
spidev with properties:
ChipSelectPin: D10
Pins: SPI-4(MOSI), SPI-1(MISO), SPI-3(SCK)
Mode: 3 (0, 1, 2 or 3)
BitOrder: msbfirst ('msbfirst' or 'lsbfirst')
BitRate: 1000000 (Hz)
And...... I'll create an "issue" in MW inner support service to research this bug and properly describe all limitations. If it was useful for you, mark the answer as accepted.
test.PNG
Massoud Tohidian
Massoud Tohidian 2019년 8월 12일
Thanks so much. Please also note that Mode is not properly set to 3, and it is still in Mode 0. In Mode 3 data should be stable at falling edge, not rising.
I appreciate if you could follow it up with Mathworks and post here again any solution you find.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Massoud Tohidian
Massoud Tohidian 2019년 8월 6일
편집: Massoud Tohidian 2019년 8월 6일
Yes fore sure I have created the system object beforehand. Here is the complete code:
a = arduino()
dev = spidev(a,'D10','Mode',3,'Bitrate',1000000)
writeRead(dev,15);
And it returns this:
a =
arduino with properties:
Port: 'COM3'
Board: 'Due'
AvailablePins: {'D2-D53', 'A0-A11'}
Libraries: {'I2C', 'SPI', 'Servo'}
dev =
spidev with properties:
ChipSelectPin: D10
Pins: SPI-4(MOSI), SPI-1(MISO), SPI-3(SCK)
Mode: 3 (0, 1, 2 or 3)
BitOrder: msbfirst ('msbfirst' or 'lsbfirst')
BitRate: 1000000
But in real measured bitrate (on oscilloscope) is still 4Mbps and in Mode 0.
  댓글 수: 2
Andrey Kiselnikov
Andrey Kiselnikov 2019년 8월 13일
"The 'spidev' function is being replaced by the 'device' function, which may perform better in this situation. " Hi, can you try this way?
Massoud Tohidian
Massoud Tohidian 2019년 8월 13일
Both are tried. No difference. I guess something is wrong with Arduino’s Firmware.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by