Hi Philippe,
It seems that your code contains sending of address and data in two block (SendBlock method). To minimize the delay you must use SendBlock method and send address and data in one block (the SPIMaster_LDD code is optimized for this usage). You can use a structure where the addr and val are defined e.g.
typedef struct {
uint8_t addr;
uint8_t val;
} tData;
Then the code of your SpiWriteReg function can be following:
static uint8_t SpiWriteReg(uint8_t addr, uint8_t val) {
tData data;
// data preparation for sending in one block of data
data.addr = addr;
data.val = val;
// dummy variable for receiving of data
uint8_t dummy[2];
SPI_CS_ENABLE();
// send and receive of address and value
(void)SM1_ReceiveBlock(SM1_DeviceData, &dummy, sizeof(tData));
(void)SM1_SendBlock(SM1_DeviceData, &data, sizeof(tData));
// wait for receiving of the block of data
while(!SM1_GetBlockReceivedStatus(SM1_DeviceData)){}
SPI_CS_DISABLE();
return ERR_OK;
}
Please, note that you can also use GetBlockReceiveStatus method of the SPIMaster_LDD component. You will find it when you switch to Advanced view mode in to the Component Inspector and enable generation of this method.
For more information about SPIMaster_LDD see the help of this component accessible using pop-up menu of the component in the components view(description of methods and Typical Usage).
Best Regards,
Marek Neuzil