IQuestion about SPIMaster_LDD in KDS

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

IQuestion about SPIMaster_LDD in KDS

577 次查看
sburck
Contributor I

I'm writing an SPI driver to a device which requires me to either send small commands (1 byte), or to send and receive one byte.  However, the send and receive must be done under a single chip select.  If I use the built in chip select, then switching from SendBlock to ReceiveBlock lowers it, and it fails.  If I remove the chip select and handle it as an IO, I have timing problems, as the event for send comes after the last byte (in my case also the first) has entered the buffer - but before the character has actually been transmitted - so I have to do a forced wait estimating when it will be ready.  Is there a way to send and receive under a single chip select with the component?

0 项奖励
1 回复

287 次查看
marek_neuzil
NXP Employee
NXP Employee

Hello,

The SPI device receive and send bytes concurrently. When a byte of data is send a byte of data is received concurrently. There shouldn't by any problem to send and receive one byte of data on a single chip select. To perform this action by using SPIMaster, you must call the receive function firstly (it just assign a buffer for received data) and then send the data by the send function.

See for example the following code (it is available in the Typical usage chapter in the SPIMaster_LDD help):

#define BLOCK_SIZE 4

uint8_t OutData[BLOCK_SIZE] = "0123";

uint8_t InpData[BLOCK_SIZE];

volatile bool DataReceivedFlag = FALSE;

volatile LDD_SPIMASTER_TError ComError = 0U;

LDD_TError Error;

LDD_TDeviceData *MySPIPtr;

void main(void)

{

  ...

  MySPIPtr = SM1_Init(NULL);                               /* Initialization of SM1 component */

  Error = SM1_ReceiveBlock(MySPIPtr, InpData, BLOCK_SIZE); /* Request data block reception */

  Error = SM1_SendBlock(MySPIPtr, OutData, BLOCK_SIZE);    /* Start transmission/reception */

  while (!DataReceivedFlag) {};                            /* Wait until data block is transmitted/received */

}

Best Regards,

Marek Neuzil

0 项奖励