SPI with Multiple Devices (One is an SD Card)

cancel
Showing results for 
Search instead for 
Did you mean: 

SPI with Multiple Devices (One is an SD Card)

1,625 Views
Contributor IV

I am developin my application with CW 10.4 and MQX 4.0.2 on my K60-base custom board.

I used SPIMaster_LDD in my BSP to communicate with 2 data-flash memories through SPI0 in Mode-3.

Now I was asked to add an SD card connected to the same SPI0 bus and to mount a file system on it.

I have 2 problem to face:

  1. For SD card the SPI0 bus must be configured in a different way (Mode-0 with different baud rate)
  2. There is a MQX sample code for using MFS on a SD card with SPI, but that code is not based on a BSP library generated with Processor Expert, i.e. the demo uses the MQX IO SPI Driver.

Should I use MQX IO SPI driver in my BSP for all thedevices connected to the SPI0 bus?


Labels (1)
Tags (1)
0 Kudos
5 Replies

145 Views
Senior Contributor I

Hello,

Where did you find the SD card demo based on the SPI?

Thanks.

-Daniel

0 Kudos

145 Views
NXP Employee
NXP Employee

Regarding using Filesystem, I don't know it there is a possibility to connect to MQX filesysten, but you can see this article that shows how to communicate with SD card and use File-system with Processor Expert on FRDM-KL25:

Arduino Data-Logger Shield with the FRDM-KL25Z Board | MCU on Eclipse

best regards

Petr Hradsky

Processor Expert Support Team

0 Kudos

145 Views
NXP Employee
NXP Employee

There is another tutorial which uses SPI SD Card and W5100 on the same SPI bus:

FRDM with Arduino Ethernet Shield R3, Part 2: Ping | MCU on Eclipse

0 Kudos

145 Views
Contributor II

HI, I am very new to Freescale Kinetic microcontrollers. I am working on FRDM-k20d50m development board and trying to develop an application to interface two slaves on this development board. My requirement is to send data to 1st slave and then receive data from the same slave and then to deploy same operation on 2nd slave. If I am using one slave at a time and disconnect the other one then it works fine but if I connect two slaves the at same time I am not receiving any data from slave. The basic code to initiate SPI communication between two slaves is as below:

/* Below block of code writes/reads data from first slave*/

  SM1_SelectConfiguration(SPI, ChipSelect, AttributeSet);

  SM1_SendBlock(SPI, out_data, sizeof (out_data));

  SM1_ReceiveBlock(SPI, &in_data, sizeof (in_data));

  /* Below block of code writes/reads data from second slave*/

  SM1_SelectConfiguration(SPI, ChipSelect_1, AttributeSet_1);

    SM1_SendBlock(SPI, out_data, sizeof (out_data));

        SM1_ReceiveBlock(SPI, &in_data_1, sizeof (in_data_1));

Please help me to make the communication possible with two slaves at the same time with proper toggling.

0 Kudos

145 Views
NXP Employee
NXP Employee

Hi,

I think there are two issues here:


1. You need to call ReceiveBlock first instead of what you have in your post, because the clock is generated after the transfer is performed.

2. Your code does not wait for the result. Please note that the component methods do not wait for the operation to end, the transfer just puts the value to the HW output buffer. You can use SM1_GetBlockReceivedStatus method for checking that the data are completely sent.

It should look like this:

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

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

while (!SM1_GetBlockReceivedStatus(MySPIPtr)) {}; // wait for the transaction to finish

...

You can find examples at the Typical usage page of the SPIMaster_LDD component help which you can get using the pop-up menu command "Help on component" 


best regards

Petr Hradsky

Processor Expert Support Team

0 Kudos