LPSPI how to send and receive data from three slave devices

cancel
Showing results for 
Search instead for 
Did you mean: 

LPSPI how to send and receive data from three slave devices

611 Views
Contributor I

Hello, My project uses SPI2 to connect three slave devices, use LPSPI_PCS0, LPSPI_PCS1, LPSPI_PCS2, how to send and receive data to each slave device.

...

LPSPI_DRV_MasterInit(SPI2_0, &masterState, &lpspiCom3_MasterConfig0);
LPSPI_DRV_MasterInit(SPI2_1, &masterState, &lpspiCom3_MasterConfig1);
LPSPI_DRV_MasterInit(SPI2_2, &masterState, &lpspiCom3_MasterConfig2);
while(1)
{

   delay(1000);
   LPSPI_DRV_MasterTransferBlocking(SPI2_0, &masterDataSend, &masterDataReceive, BUFFER_SIZE, TIMEOUT);

   LPSPI_DRV_MasterTransferBlocking(SPI2_1, &masterDataSend, &masterDataReceive, BUFFER_SIZE, TIMEOUT);

   LPSPI_DRV_MasterTransferBlocking(SPI2_2, &masterDataSend, &masterDataReceive, BUFFER_SIZE, TIMEOUT);
}

Is that right?     SPI2_0, SPI2_1,SPI2_2 value is how much?

Please help me.

Thank you.

Best Regards.

0 Kudos
3 Replies

21 Views
Contributor I

The problem is solved, the use of any one slave device, you must re-initialize the configuration data, and then you can send and receive data. thank you all.

Best Regards.

0 Kudos

21 Views
Contributor I

Look at my configuration map

2.bmp

4.bmp

const lpspi_master_config_t lpspiCom3_MasterConfig0 = {
.bitsPerSec = 500000U,
.whichPcs = LPSPI_PCS0,
.pcsPolarity = LPSPI_ACTIVE_LOW,
.isPcsContinuous = true,
.bitcount = 8U,
.lpspiSrcClk = 8000000U,
.clkPhase = LPSPI_CLOCK_PHASE_2ND_EDGE,
.clkPolarity = LPSPI_SCK_ACTIVE_LOW,
.lsbFirst = false,
.transferType = LPSPI_USING_INTERRUPTS,
.rxDMAChannel = 255,
.txDMAChannel = 255,
};

const lpspi_master_config_t lpspiCom3_MasterConfig1 = {
.bitsPerSec = 500000U,
.whichPcs = LPSPI_PCS1,
.pcsPolarity = LPSPI_ACTIVE_LOW,
.isPcsContinuous = true,
.bitcount = 8U,
.lpspiSrcClk = 8000000U,
.clkPhase = LPSPI_CLOCK_PHASE_2ND_EDGE,
.clkPolarity = LPSPI_SCK_ACTIVE_LOW,
.lsbFirst = false,
.transferType = LPSPI_USING_INTERRUPTS,
.rxDMAChannel = 255,
.txDMAChannel = 255,
};

const lpspi_master_config_t lpspiCom3_MasterConfig2 = {
.bitsPerSec = 500000U,
.whichPcs = LPSPI_PCS2,
.pcsPolarity = LPSPI_ACTIVE_LOW,
.isPcsContinuous = true,
.bitcount = 8U,
.lpspiSrcClk = 8000000U,
.clkPhase = LPSPI_CLOCK_PHASE_2ND_EDGE,
.clkPolarity = LPSPI_SCK_ACTIVE_LOW,
.lsbFirst = false,
.transferType = LPSPI_USING_INTERRUPTS,
.rxDMAChannel = 255,
.txDMAChannel = 255,
};

I was wondering how to initialize and how to call a function to receive and send data to each slave

Thank you.

Best Regards.

0 Kudos

21 Views
NXP Employee
NXP Employee

Hi,

The first paramter of the LPSPI functions is the instance number.

You want to use only one LPSPI device to control all the slaves or you want to control each slave with one master device?

Best regards,

Razvan

0 Kudos