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.