writeRead on SPI devices

5 ビュー (過去 30 日間)
gdz
gdz 2022 年 12 月 16 日
回答済み: Harshit Saini 2022 年 12 月 22 日
Hi Matlab Community,
I would like to communicate with SPI device (MAX6675) on matlab. However, I found a link that Communicate with SPI Device on Arduino® Hardware and I am doubt with the function writeRead because I couldn't find more detail explaination on writeRead function. It required two inputs, dev and dataIn. What did dataIn does exactly?
writeRead(d_pot, [hex2dec('12'), regVal], 'uint8');
In the example https://www.mathworks.com/help/supportpkg/arduinoio/examples/communicate-with-spi-device-on-arduino-hardware.html , the dataIn is [hex2dec('12'), regVal]. What did dataIn do to the d_pot exactly?
I also don't understand the outpot of writeRead in the figure(capture).
Please help me if you have any thought on this. Thank you.

採用された回答

Harshit Saini
Harshit Saini 2022 年 12 月 22 日
To communicate with SPI devices, you can use the single “writeRead” function to both write or read data to the device. It takes in two inputs: dev and dataIn.
  • Dev refers to the connected SPI device object.
  • DataIn refers to the data which you want to write or read from the connected device. DataIn takes input as multiple formats (scalar, vector, hexadecimal, or binary). This format is dependent on the SPI device. The format is specified in the datasheet for the device which you are communicating with. In the examples, the dataIn values are different depending on which device is used. The EEPROM accepts data as [writeCmd address data]. The writeCmd is used as a flag to indicate that the data needs to be written at the specified address.
Additionally, the output is returned as a vector of zeros to indicate that the write operation was successful. As the “writeRead” function is used to read and write from a device, the returned output refers to the read operation of the function. Since, there is no read operation taking place when we are writing to the device, the output is zero. Zero indicates a successful write operation.
Refer to the datasheet of MAX6675 to understand the data format required to communicate with the device.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTroubleshooting in MATLAB Support Package for Arduino Hardware についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by