![Ratoc Systems REX-USB61 User Manual Download Page 73](http://html.mh-extra.com/html/ratoc-systems/rex-usb61/rex-usb61_user-manual_788102073.webp)
4. API function reference
Page.4-28
Example - EEPROM R/W Utility [SPI] :
Output a byte 'FF' hex-decimal data from SDO line. (C++)
It does not include error handling.
// Output a byte ‘FF’ hex-decimal data from SDO line
// Send [Write command(0x02) + EEPROM address(0x0000) + data for writing(0xff)] 4bytes
pWriteBuf[0] = 0x02 // Write command
pWriteBuf[1] = 0x00 // EEPROM address(upper byte)
pWriteBuf[2] = 0x00 // EEPROM address(lower byte)
pWriteBuf[3] = 0xff
// Data for writing
DataLen = 4
// Transfer length
usb61_spi_transmit_master( hDeviceHandle, RS_SPI_SS0, DataLen, pWriteBuf, pReadBuf );
// In reading, after the fourth of byte are data.
// Finish using the REX-USB61 device
usb61_close(hDeviceHandle);
hDeviceHandle
=
NULL;
pWriteBuf[0] = 0x06; // WREN command
DataLen = 1
// Transfer length
usb61_spi_transmit_master( hDeviceHandle, RS_SPI_SS0, DataLen, pWriteBuf, pReadBuf );
// Send the Write Enable command(0x06)
HANDLE hDeviceHandle;
// Device handle
WORD DataLen;
// Transfer length
USHORTspiFreq;
//
Operating
frequency
WORD
ActualFreq;
//
Actual
frequency
BYTE pWriteBuf;
// Store data for writing
BYTE pReadBuf;
// Store data for reading
UINT uiFlag;
// bit combination of clock leading or trailing, polarity
// Get device handle
hDeviceHandle
=
usb61_open(&rsStatus);
// Supply 5.0V power to target device.
// Using the source power from target device without from REX-USB61,
// Set RS_PWRCTRL_OFF
usb61_power_control(hDeviceHandle, RS_PWRCTRL_ON | RS_OUTPUT_5_0V);
// Set SPI master mode
usb61_mode_change(hDeviceHandle,
RS_DEVMODE_SPI | RS_DEVMODE_MASTER, NULL );
// Set Interval (After SPI mode changed)
usb61_set_interval(hDeviceHandle, IntervalCnt);
// Set frequency
uiFlag = RS_SPI_PHASE_SAMPLE_SETUP | RS_SPI_POLARITY_POSITIVE
| RS_SPI_MSB_FIRST;
usb61_spi_set_freq(
hDeviceHandle,
uiFlag, spiFreq, &ActualFreq );