writeRead on SPI devices

9 views (last 30 days)
gdz
gdz on 16 Dec 2022
Answered: Harshit Saini on 22 Dec 2022
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.

Accepted Answer

Harshit Saini
Harshit Saini on 22 Dec 2022
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.

More Answers (0)

Tags

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!