HEllo ,
I'm using a FRDM board to send SPI command to an external part with processor expert and SM1: SPImaster_LDD component.
here below the component configuration :
To send a SPI write command I used the following functions and it's working fine:( I 'm using a GPIO to drive the CS)
static uint8_t SpiWriteReg(uint8_t addr, uint8_t val) {
SPI_CS_ENABLE();
SPIWriteByte(addr); /* address */
SPIWriteByte(val) ; /* data */
SPI_CS_DISABLE();
return ERR_OK;
}
static void SPIWriteByte(unsigned char write) {
unsigned char dummy;
(void)SM1_ReceiveBlock(SM1_DeviceData, &dummy, sizeof(dummy));
(void)SM1_SendBlock(SM1_DeviceData, &write, sizeof(write));
while(!spi_DataReceivedFlag){}
}
But I have a problem with such commands, because there is a delay between both SPIWriteByte(adrr) & SPIWriteByte(val).
Could someone explain me how to send the same information without any delay as shown in the below picture:
Thanks for your help
Rgds
Philippe
解決済! 解決策の投稿を見る。
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
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
Hello Marek,
thanks for your help. that is what I was looking for.
Rgds
Philippe