LPSPI how to send and receive data from three slave devices

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

LPSPI how to send and receive data from three slave devices

2,342 次查看
jia_xuan
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 项奖励
回复
4 回复数

638 次查看
Kowshik-28
Contributor I

Hi, 
I am unable to get the LPSPI0 communication sending and receiving problem. here is the below code and PINsettings 

CLOCK_DRV_Init(&clockMan1_InitConfig0);
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
LPSPI_DRV_MasterInit(LPSPICOM1,&lpspiCom1State,&lpspiCom1_MasterConfig0);
uint8_t sending[1];
sending[0]=0x1;
uint8_t receving[1];
while(1)
{
//sending[0]=0x1;
LPSPI_DRV_MasterTransferBlocking(LPSPICOM1,sending,receving,(uint16_t)1,OSIF_WAIT_FOREVER);
    printf("Received: 0x%02X\n", receving[0]);
 
}
Screenshot 2024-01-12 102940.png
OUTPUT:
Screenshot 2024-01-12 105829.png
here we have not connected the MISO but MOSI it self showing me the default data so if any corrections to be made plz tell me
0 项奖励
回复

1,752 次查看
jia_xuan
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 项奖励
回复

1,752 次查看
jia_xuan
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 项奖励
回复

1,752 次查看
razva_tilimpea
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 项奖励
回复