TsctlSPIWriteCExamples

From embeddedTS Manuals
// Do an SPI write transaction to an FPGA expecting a four byte
// sequence of command, address, 16-bit data
void SPIRegisterWrite(SPI *spi,int adrs,unsigned short data) {
  // First, create a 4 element libtsctl array of char
  ArrayAutoOfSize(unsigned char, spiData, 4);

  // Initialize the array for the transaction
  spiData[0] = 0XE0;
  spiData[1] = adrs;
  spiData[2] = data >> 8;
  spiData[3] = data & 0xff;

  // Lock SPI, do the transaction, and unlock
  spi->Lock(spi, 0, 0);
  spi->Write(spi, 4, spiData);
  spi->Unlock(spi, 0, 0);
}