Multi slaves SPI (NXP MBD S32K11x)

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Multi slaves SPI (NXP MBD S32K11x)

1,757件の閲覧回数
viet
Contributor II

Hi @marius

According to our requirement, we need to have S32K118 (plays as spi master role) and connect to other 4 spi slave devices:

viet_0-1630380932756.png

Because of the S32K118 SPI block, support only 2 Chip Select, so we decided that try to use the GPIO as the Chip Select, and left blank the PCSx in the SPI block configuration. So our connection like below (connect 4 GPIOs to 4 Spi slaves, respectively):

viet_5-1630381801222.png

viet_3-1630381599904.png

For starting the communication with SPI Slave 1, we need pull low GPIO 1, pull high other 3 GPIO and start send data over SPI from S32K118. 

Look good !

But then we investigate in generated code, we saw that NXP MBD using PCS0 as default. Every time we use the "LPSPI_Master_Transfer" block to transfer data, it will set low the PCS0, then send data.

viet_6-1630382196447.png


so with the result in generated code, we are not able to communicate with multi spi slaves.

Please give us your comments on this issue. Does any other way for us to have multi spi slaves model ?

thanks 
Viet

 

 

 

 

 

0 件の賞賛
返信
3 返答(返信)

1,747件の閲覧回数
mariuslucianand
NXP Employee
NXP Employee

Hello @viet,

You can select which PCS to be used on each transfer from the LPSPI Master Transfer Block, the PCS dropdown.

mariuslucianand_1-1630403797022.png

The problem is that your application requires 4 Chip Select signals, as you have described and on this MCU only 2 chip-select signals are available. 

However, you can still use the S32K118 for your application. My suggestion here is to use a GPIO block for each Slave, as CS. Before the transfer, you have to clear the CS pin with the GPIO block and set the CS pin once the transfer has ended. Let me know if you want me to give you more details on that.

Hope this helps,

Marius

 

 

 

0 件の賞賛
返信

1,739件の閲覧回数
viet
Contributor II

Hi @mariuslucianand 

Thanks for your response quickly. 

Really appreciate about your suggestion. We currently design same as your suggestion. 
small piece of generated code below will tell you more : 

  /* Output and update for function-call system: '<Root>/Subsystem' */

  /* S-Function (gpio_s32k_output): '<S6>/__' incorporates:
   *  Constant: '<S2>/Constant'
   */

  /* GPOPORTD3 Data Signal Update */
  if (false) {
    PINS_DRV_SetPins(PTD, 1UL<<3);
  } else {
    PINS_DRV_ClearPins(PTD, 1UL<<3);
  }

  /* S-Function (gpio_s32k_output): '<S6>/_' incorporates:
   *  Constant: '<S2>/Constant1'
   */

  /* GPOPORTE3 Data Signal Update */
  if (true) {
    PINS_DRV_SetPins(PTE, 1UL<<3);
  } else {
    PINS_DRV_ClearPins(PTE, 1UL<<3);
  }

  /* S-Function (gpio_s32k_output): '<S6>/ ' incorporates:
   *  Constant: '<S2>/Constant2'
   */

  /* GPOPORTE0 Data Signal Update */
  if (true) {
    PINS_DRV_SetPins(PTE, 1UL<<0);
  } else {
    PINS_DRV_ClearPins(PTE, 1UL<<0);
  }

  /* S-Function (gpio_s32k_output): '<S6>/____' incorporates:
   *  Constant: '<S2>/Constant3'
   */

  /* GPOPORTA3 Data Signal Update */
  if (true) {
    PINS_DRV_SetPins(PTA, 1UL<<3);
  } else {
    PINS_DRV_ClearPins(PTA, 1UL<<3);
  }

  /* S-Function (lpspi_s32k_master_transfer): '<S7>/LPSPI_Master_Transfer3' incorporates:
   *  Constant: '<S7>/Constant3'
   */
  {
    /* Update the peripheral CS to select the slave you want to send data to */
    LPSPI_DRV_SetPcs(1, LPSPI_PCS0, LPSPI_ACTIVE_LOW);

    /* Send data */
    LPSPI_DRV_MasterTransferBlocking(1, msdi_attemptViet_ConstP.pooled4,
      &msdi_attemptViet_B.LPSPI_Master_Transfer3[0], 3, 10);
  }

we clear the GPIO which is connected to SPI slave that we want to transfer data to.
But, in the generated code above, there is the line : 

 LPSPI_DRV_SetPcs(1, LPSPI_PCS0, LPSPI_ACTIVE_LOW);

does it clear the LPSPI_PCS0 pin ? 
and if it does, it will impact to our hw design, because when we want transfer data to other SPI slave. 
NXP MBD keep generating the " LPSPI_DRV_SetPcs(1, LPSPI_PCS0, LPSPI_ACTIVE_LOW);"

thanks
Viet

0 件の賞賛
返信

1,692件の閲覧回数
mariuslucianand
NXP Employee
NXP Employee

Hello @viet ,

I am glad that we've embraced the same approach for addressing multiple SPI devices on S32K118.

However, you have to tweak the generated code for the blocks in order to make sure that you send/receive data to/from only one slave device. You can specify the order on how the code should be generated by setting the priorities of the blocks. You can set this by right click on the block, select Properties, and set a numeric value in the Priority. 

2.PNG

I can see in your code that when you select the PTD1 CS (pull it low) the others you pull high, to not communicate with the remaining devices, which is ok. But my suggestion is that once you end that transfer, pull the PTD1 again to high. In this way, you won't need that each time you communicate, to set the other CS pins again. See below an example.

3.PNG

Now, you are right regarding the CS pin selection each time in the generated code. What I would suggest is either to leave that pin unconnected, or you may also could try to select a value of 2 or 3, which of course should not be connected to any pin. However, the last idea has to be tested on the board.

Hope this helps,

Marius

0 件の賞賛
返信