Writing configuration data to registers

Hello I am working on a project where I am interfacing an Arduino Uno with an IC device. I am trying to make a write method/function that writes configuration data to configuration registers.

I used an example document as a reference, and here is their write method (written for an STM32F105_VC microprocessor):

/*******************************************************************************
 * Function Name: gp22_wr_config_reg
 * Parameters: Address byte, 4 bytes of Configuration
 *
 * Return: none
 *
 * Description: Writes the config.reg. specified in GP21 with the data 
 *
 ******************************************************************************/
void gp22_wr_config_reg (void *bus_type, uint8_t opcode_address,
                         uint32_t config_reg_data)
{
   uint8_t Data_Byte_Lo    = config_reg_data;
   uint8_t Data_Byte_Mid1  = config_reg_data>>8;
   uint8_t Data_Byte_Mid2  = config_reg_data>>16;
   uint8_t Data_Byte_Hi    = config_reg_data>>24;

   uint8_t common_delay    = 10; // important delay (16) at SPI freq.=750kHz
   
      // Deactivating Reset SPIx
      if (bus_type==SPI1) GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
      if (bus_type==SPI2) GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_RESET);
      
      while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {} 

      SPI_I2S_SendData(bus_type, opcode_address);  // RAM WR OPCODE+ADDRESS
  Simple_delay_750ns((void*)common_delay);

      while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
      SPI_I2S_SendData(bus_type, Data_Byte_Hi);  // DATA BYTE HIGH 
  Simple_delay_750ns((void*)common_delay);

      while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
       SPI_I2S_SendData(bus_type, Data_Byte_Mid2);  // DATA MID - 2 
  Simple_delay_750ns((void*)common_delay);

      while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
       SPI_I2S_SendData(bus_type, Data_Byte_Mid1);  // DATA MID - 1
  Simple_delay_750ns((void*)common_delay);

      while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
       SPI_I2S_SendData(bus_type, Data_Byte_Lo);  // DATA LOW
  Simple_delay_750ns((void*)common_delay);

      while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
  Simple_delay_750ns((void*)common_delay);
      
     // Reset to device SPIx
     if (bus_type==SPI1) GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
     if (bus_type==SPI2) GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_SET);
}

And here is the write method that I have written for the Arduino:

void writeConfig( byte regAd, uint32_t regData){
  /*Since the SPI.transfer function can only transfer one byte at a time,
  it is necessary to decompose the 4 bytes of configuration data into 
  1 byte segments.  The following byte variables are the four components of 
  the registration data.
  */
  byte configByteLow = regData;  //the least 4 significant bytes
  byte configByteMid1 = regData>>8; //subsequent 4 bytes
  byte configByteMid2 = regData>>16; //subsequent 4 bytes
  byte configByteHi = regData>>24;  //the highest 4 significant bytes
  
  
  delayMicroseconds(100);   
  SPI.transfer(regAd);  //transfers register address to be written to
  //******Not sure if we need LSB or MSB first.  NEED TO CHECK*****
  //transfers 4 components of configuration data
  SPI.transfer(configByteLow);  
  delayMicroseconds(100); 
  SPI.transfer(configByteMid1);
  delayMicroseconds(100); 
  SPI.transfer(configByteMid2);
  delayMicroseconds(100); 
  SPI.transfer(configByteHi);
  delayMicroseconds(100); 
  digitalWrite(slaveSelectPin, HIGH);  //deselects gp22

When I pass the configuration register address to the Arduino, how will it know what to do with the byte value? How will it know that it is a config register address?

Also, I am not sure if the way I wrote the method/function is correct for writing to registers...

Thanks,
Anthony

bmell:
When I pass the configuration register address to the Arduino, how will it know what to do with the byte value? How will it know that it is a config register address?

Are you writing to an Arduino or some other device on the SPI bus?

In either case, when the slave device sees the Slave Select line go LOW it knows that data provided with the next 8 clock cycles are for the address.

You probably don't need the 100 microseconds delays between transactions.

I am writing the configuration data values to a slave device, not the arduino.

How will I know if the slave device has received the correct config values? I am confused as how to write code to read registers off of a slave device.

bmell:
I am writing the configuration data values to a slave device, not the arduino.

How will I know if the slave device has received the correct config values? I am confused as how to write code to read registers off of a slave device.

An SPI device looks a lot like a Serial In/Serial Out shift register. For every clock pulse one bit from MOSI (MasterOut/SlaveIn) is shifted into the slave device and one bit from MISO (MasterIn/SlaveOut) is shifted into the master. Each spi.transfer() does 8 clocks, sending the data passed as the argument to the function and returning the data received from the slave.

Typically to read registers you use the first transfer to send the register address and then use subsequent transfers to receive the data from the registers. Since the data sent by these 'receive' transfers doesn't matter you usually send 0.

Something like this:

uint32_t  readConfig(byte regAd) {
  uint32_t returnValue;
  
  digitalWrite(slaveSelectPin, LOW);  // selects gp22
  SPI.transfer(regAd);
  byte configByteLow = SPI.transfer(0);  
  byte configByteMid1 = SPI.transfer(0);
  byte configByteMid2 = SPI.transfer(0);
  byte configByteHi = SPI.transfer(0);
  digitalWrite(slaveSelectPin, HIGH);  // deselects gp22

  returnValue = configByteHi;
  returnValue <<= 8;
  returnValue |= configByteMid2;
  returnValue <<= 8;
  returnValue |= configByteMid1;
  returnValue <<= 8;
  returnValue |= configByteLow;
 
  return returnValue;
}