<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Talk to an SD card via SPI? in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726614#M29378</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for the late response. I was busy with other things and had parked this work aside. So slowing down the clock speed for the initialisation worked. This was something I forgot to do before. I was able to get the correct responses back for the SD commands. I m able to read and write to the SD card also so I can use it as a basic data logger, however still working on integration with the FATFS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the help.&lt;/P&gt;&lt;P&gt;Ronan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 May 2018 12:04:30 GMT</pubDate>
    <dc:creator>puddletowntom</dc:creator>
    <dc:date>2018-05-23T12:04:30Z</dc:date>
    <item>
      <title>Talk to an SD card via SPI?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726610#M29374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to communicate with an SD card using an LPC5411 dev board based on developing my own SD card custom driver. I m basing the development on the following tutorial &lt;A href="https://community.nxp.com/docs/DOC-330958"&gt;Porting FatFs file system to KL26 SPI SD card code&lt;/A&gt;&amp;nbsp; . I have the SD card connected externally to the development board. I m having a problem initialising the SD card. I have made sure of the following. I send 80 pulses of a clock signal with Chip Select high and MOSI high. After this i m setting the CS low and sending the byte values 0x40, 0x00,&amp;nbsp;&lt;SPAN&gt;0x00,&amp;nbsp;0x00,&amp;nbsp;0x00,&amp;nbsp;0x95 for CMD0. I m not receiving any byte values back on the MISO line. I was checking the scope and it appears that the CS, MOSI and CLK are working but the MISO isnt. Is there a timing issue. I have attached the screen grab of the the SPI lines.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_4.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/8262iB72EC34EC9CA6958/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_4.jpg" alt="pastedImage_4.jpg" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The code I m using the generate these pulses is as follows&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint8_t MMCInit(){&lt;BR /&gt; spi_master_config_t userConfig = {0};&lt;BR /&gt; spi_master_config_t masterConfig = {0};&lt;/P&gt;&lt;P&gt;uint8_t i = 0,k = 0,tmp = 0;&lt;BR /&gt; uint16_t cnt=0;&lt;BR /&gt; uint8_t buff[512];&lt;/P&gt;&lt;P&gt;SPI_MasterGetDefaultConfig(&amp;amp;userConfig);&lt;BR /&gt; srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ_LOW;//EXAMPLE_SPI_MASTER_CLK_FREQ;&lt;BR /&gt; masterConfig.sselNum = (spi_ssel_t)EXAMPLE_SPI_SSEL;&lt;BR /&gt; SPI_MasterInit(EXAMPLE_SPI_MASTER, &amp;amp;userConfig, srcFreq);&lt;/P&gt;&lt;P&gt;spi_transfer_t xfer = {0};&lt;BR /&gt; status_t xferStatus = kStatus_Success;&lt;/P&gt;&lt;P&gt;uint8_t ucTemp;&lt;BR /&gt; for (i = 0U; i &amp;lt; BUFFER_SIZE; i++)&lt;BR /&gt; {&lt;BR /&gt; srcBuff[i] = 0xFF;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;xfer.txData = srcBuff;&lt;BR /&gt; xfer.rxData = destBuff;&lt;BR /&gt; xfer.dataSize = sizeof(destBuff);&lt;/P&gt;&lt;P&gt;// SPI_CS_Low();&lt;BR /&gt; xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &amp;amp;xfer);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; //40 00 00 00 00 95 for CMD0&lt;BR /&gt; //48 00 00 01 AA 0F for CMD8&lt;BR /&gt; //7A 00 00 00 00 75&lt;/P&gt;&lt;P&gt;startCMD[0] = 0x40;&lt;BR /&gt; startCMD[1] = 0x00;&lt;BR /&gt; startCMD[2] = 0x00;&lt;BR /&gt; startCMD[3] = 0x00;&lt;BR /&gt; startCMD[4] = 0x00;&lt;BR /&gt; startCMD[5] = 0x95;&lt;BR /&gt;// xfer.configFlags = kSPI_FrameAssert;&lt;/P&gt;&lt;P&gt;xfer.txData = startCMD;&lt;BR /&gt; xfer.rxData = endBuff;&lt;BR /&gt; xfer.dataSize = 7;//sizeof(endBuff); 6 bytes and one more&lt;BR /&gt; SPI_CS_Low();&lt;BR /&gt; xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &amp;amp;xfer);&lt;BR /&gt; SPI_CS_High();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;uint8_t MMCInit(){ spi_master_config_t userConfig = {0}; spi_master_config_t masterConfig = {0}; uint8_t i = 0,k = 0,tmp = 0; uint16_t cnt=0; uint8_t buff[512]; SPI_MasterGetDefaultConfig(&amp;amp;userConfig); srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ_LOW;//EXAMPLE_SPI_MASTER_CLK_FREQ; masterConfig.sselNum = (spi_ssel_t)EXAMPLE_SPI_SSEL; SPI_MasterInit(EXAMPLE_SPI_MASTER, &amp;amp;userConfig, srcFreq); spi_transfer_t xfer = {0}; status_t xferStatus = kStatus_Success; uint8_t ucTemp; for (i = 0U; i &amp;lt; BUFFER_SIZE; i++) { srcBuff[i] = 0xFF; } xfer.txData = srcBuff; xfer.rxData = destBuff; xfer.dataSize = sizeof(destBuff); // SPI_CS_Low(); xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &amp;amp;xfer); //40 00 00 00 00 95 for CMD0 //48 00 00 01 AA 0F for CMD8 //7A 00 00 00 00 75 startCMD[0] = 0x40; startCMD[1] = 0x00; startCMD[2] = 0x00; startCMD[3] = 0x00; startCMD[4] = 0x00; startCMD[5] = 0x95; // xfer.configFlags = kSPI_FrameAssert; xfer.txData = startCMD; xfer.rxData = endBuff; xfer.dataSize = 7;//sizeof(endBuff); 6 bytes and one more SPI_CS_Low(); xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &amp;amp;xfer); SPI_CS_High(); }&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Apr 2018 15:48:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726610#M29374</guid>
      <dc:creator>puddletowntom</dc:creator>
      <dc:date>2018-04-12T15:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Talk to an SD card via SPI?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726611#M29375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ronan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Please send me your test project, I will help you to check it on my side.&lt;/P&gt;&lt;P&gt;&amp;nbsp; Please also tell me which pins you are using in the LPC5411X.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Kerry&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Apr 2018 07:01:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726611#M29375</guid>
      <dc:creator>kerryzhou</dc:creator>
      <dc:date>2018-04-16T07:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Talk to an SD card via SPI?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726612#M29376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kerry,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Last Friday I made some progress. I started to see something on the MISO line. For the reset command, eg&amp;nbsp;&amp;nbsp;MMCWriteCmd(CMD0,0x00,0x95);&amp;nbsp; &amp;nbsp;it seemed like I was receiving the expected value back. eg the 1 value (00000001). However, I think I was receiving a decimal value of 9 for the CMD8 command. eg MMCWriteCmd( CMD8,0x1AA,0x87 ); I dont really know why this is. I have attached a screen grab to show that there is in fact something on the MISO line. However I m not sure if my clock sequence is correct. If I send&amp;nbsp;a byte using the&amp;nbsp;SPI_MasterTransferBlocking() command for each individual byte then I wont have a continuous clock. For the 72 clock pulses does the clock need to be continuous or can it be broken up?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Chip Select(Green) ==&amp;gt; (GPIO pin) port0_pin10&lt;/P&gt;&lt;P&gt;Clock(Purple) ==&amp;gt;&amp;nbsp;port0_pin19&lt;/P&gt;&lt;P&gt;MOSI(Yellow) ==&amp;gt;&amp;nbsp;port0_pin20&lt;/P&gt;&lt;P&gt;MISO(Blue) ==&amp;gt;&amp;nbsp;port0_pin18,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I m not certain that the way I m using the Send_Byte() function is correct. The code I last worked on is attached below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_1.jpg"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/10902iF8E0CF813E3B8158/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_1.jpg" alt="pastedImage_1.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&lt;BR /&gt; * Copyright (c) 2016, Freescale Semiconductor, Inc.&lt;BR /&gt; * Copyright 2016-2017 NXP&lt;BR /&gt; *&lt;BR /&gt; * Redistribution and use in source and binary forms, with or without modification,&lt;BR /&gt; * are permitted provided that the following conditions are met:&lt;BR /&gt; *&lt;BR /&gt; * o Redistributions of source code must retain the above copyright notice, this list&lt;BR /&gt; * of conditions and the following disclaimer.&lt;BR /&gt; *&lt;BR /&gt; * o Redistributions in binary form must reproduce the above copyright notice, this&lt;BR /&gt; * list of conditions and the following disclaimer in the documentation and/or&lt;BR /&gt; * other materials provided with the distribution.&lt;BR /&gt; *&lt;BR /&gt; * o Neither the name of the copyright holder nor the names of its&lt;BR /&gt; * contributors may be used to endorse or promote products derived from this&lt;BR /&gt; * software without specific prior written permission.&lt;BR /&gt; *&lt;BR /&gt; * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND&lt;BR /&gt; * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED&lt;BR /&gt; * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&lt;BR /&gt; * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR&lt;BR /&gt; * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES&lt;BR /&gt; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;&lt;BR /&gt; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON&lt;BR /&gt; * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT&lt;BR /&gt; * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;BR /&gt; * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;BR /&gt; */&lt;/P&gt;&lt;P&gt;#include "board.h"&lt;BR /&gt;#include "fsl_debug_console.h"&lt;BR /&gt;#include "fsl_spi.h"&lt;/P&gt;&lt;P&gt;#include "pin_mux.h"&lt;BR /&gt;#include &amp;lt;stdbool.h&amp;gt;&lt;BR /&gt;#include "ff.h"&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Definitions&lt;BR /&gt; ******************************************************************************/&lt;/P&gt;&lt;P&gt;#define EXAMPLE_SPI_MASTER SPI5&lt;BR /&gt;#define EXAMPLE_SPI_MASTER_IRQ FLEXCOMM5_IRQn&lt;BR /&gt;#define EXAMPLE_SPI_MASTER_CLK_SRC kCLOCK_Flexcomm5&lt;BR /&gt;//#define EXAMPLE_SPI_MASTER_CLK_FREQ CLOCK_GetFreq(kCLOCK_Flexcomm5)&lt;/P&gt;&lt;P&gt;#define EXAMPLE_SPI_MASTER_CLK_FREQ_LOW 20000000//20000000 //SSP0LowSpeed()&lt;BR /&gt;#define EXAMPLE_SPI_MASTER_CLK_FREQ_HIGH //4000000 //SSP0LowSpeed()&lt;/P&gt;&lt;P&gt;#define EXAMPLE_SPI_SLAVE SPI5&lt;BR /&gt;#define EXAMPLE_SPI_SLAVE_IRQ FLEXCOMM5_IRQn&lt;BR /&gt;#define EXAMPLE_SPI_SSEL 2&lt;/P&gt;&lt;P&gt;#define CORE_CLK_FREQ CLOCK_GetFreq(kCLOCK_CoreSysClk)&lt;/P&gt;&lt;P&gt;#define CMD0 0x40 //Use SPI interface&lt;BR /&gt;#define CMD8 0x48 //Get SD card version&lt;BR /&gt;#define CMD9 0x00 //Read CSD, get other information,&lt;BR /&gt;#define CMD12 0x00&lt;BR /&gt;#define CMD16 0x00 //Set SD card block size to 512Byte.&lt;BR /&gt;#define CMD17 0x00 //For reading the SD card send to this&lt;BR /&gt;#define CMD18 0x00&lt;BR /&gt;#define CMD24 0x00 //For writing to the SD card send to this&lt;BR /&gt;#define CMD41 0x69 //Activate SD card&lt;BR /&gt;#define CMD55 0x77 //Activate SD card&lt;BR /&gt;#define CMD58 0x00&lt;BR /&gt;#define CMD59 0x00 //Read OCR data&lt;/P&gt;&lt;P&gt;#define SD_TYPE_V2HC 0x04&lt;BR /&gt;#define SD_TYPE_V2 0x02&lt;/P&gt;&lt;P&gt;#define regVal1 0x00&lt;/P&gt;&lt;P&gt;#define BUFFER_SIZE (10)&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Prototypes&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;uint8_t SPI5_TransmitReceive8bit(uint8_t faidjf);&lt;BR /&gt;uint8_t spi_oled_exchange(uint8_t *in, uint8_t *out, uint32_t size);&lt;BR /&gt;void SPI_CS_High(void);&lt;/P&gt;&lt;P&gt;uint8_t MMCWriteCmd(uint8_t cmd, uint32_t arg, uint8_t crc );&lt;BR /&gt;uint32_t srcFreq = 0;&lt;BR /&gt;/*******************************************************************************&lt;BR /&gt; * Variables&lt;BR /&gt; ******************************************************************************/&lt;/P&gt;&lt;P&gt;//SPI variables&lt;BR /&gt;uint8_t SD_Type=0;&lt;BR /&gt;spi_master_config_t userConfig = {0};&lt;BR /&gt;spi_master_config_t masterConfig = {0};&lt;BR /&gt;spi_transfer_t xfer = {0};&lt;BR /&gt;status_t xferStatus = kStatus_Success;&lt;/P&gt;&lt;P&gt;static uint8_t srcBuff[BUFFER_SIZE]; //1&lt;BR /&gt;static uint8_t destBuff[BUFFER_SIZE]; //2&lt;BR /&gt;static uint8_t startCMD[1]; //1&lt;BR /&gt;static uint8_t endBuff[1]; //1&lt;/P&gt;&lt;P&gt;static uint8_t tempBuff1[1]; //1&lt;BR /&gt;static uint8_t tempBuff2[1]; //1&lt;BR /&gt;//static spi_slave_handle_t slaveHandle;&lt;BR /&gt;static volatile bool slaveFinished = false;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int testVal = 0;&lt;BR /&gt;//static uint8_t txData[16];&lt;BR /&gt;//static uint8_t rxData[16];&lt;/P&gt;&lt;P&gt;/*******************************************************************************&lt;BR /&gt; * Code&lt;BR /&gt; ******************************************************************************/&lt;BR /&gt;static void slaveCallback(SPI_Type *base, spi_slave_handle_t *handle, status_t status, void *userData)&lt;BR /&gt;{&lt;BR /&gt; slaveFinished = true;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;static void GPIO_Configuration(void)&lt;BR /&gt;{&lt;BR /&gt; CLOCK_EnableClock(kCLOCK_Gpio0);&lt;BR /&gt; CLOCK_EnableClock(kCLOCK_Gpio1);&lt;/P&gt;&lt;P&gt;const gpio_pin_config_t port0_pin2_gpio_config = {kGPIO_DigitalOutput,1,};&lt;BR /&gt; GPIO_PinInit(GPIO, PORT0_IDX, PIN2_IDX, &amp;amp;port0_pin2_gpio_config);&lt;/P&gt;&lt;P&gt;/*3.3V Enable*/&lt;BR /&gt; const gpio_pin_config_t port0_pin9_gpio_config = {kGPIO_DigitalOutput,1,};&lt;/P&gt;&lt;P&gt;GPIO_PinInit(GPIO, PORT0_IDX, PIN9_IDX, &amp;amp;port0_pin9_gpio_config);&lt;BR /&gt; SPI_CS_High();&lt;BR /&gt; //SPI_CS_Low();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void SPI_CS_Low(){&lt;BR /&gt; //Enable CS for pressure sensor.&lt;BR /&gt; const gpio_pin_config_t port0_pin10_gpio_config = {kGPIO_DigitalOutput,0,};&lt;BR /&gt; GPIO_PinInit(GPIO, PORT0_IDX, PIN10_IDX, &amp;amp;port0_pin10_gpio_config);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void SPI_CS_High(){&lt;BR /&gt; //Enable CS for pressure sensor.&lt;BR /&gt; const gpio_pin_config_t port0_pin10_gpio_config = {kGPIO_DigitalOutput,1,};&lt;BR /&gt; GPIO_PinInit(GPIO, PORT0_IDX, PIN10_IDX, &amp;amp;port0_pin10_gpio_config);&lt;BR /&gt;}&lt;BR /&gt;void timeDelay_us(uint32_t delay)&lt;BR /&gt;{&lt;BR /&gt; delay++;&lt;BR /&gt; /* Wait desired time */&lt;BR /&gt; while (delay &amp;gt; 0)&lt;BR /&gt; {&lt;BR /&gt; if (SysTick-&amp;gt;CTRL &amp;amp; SysTick_CTRL_COUNTFLAG_Msk)&lt;BR /&gt; {&lt;BR /&gt; delay--;&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void timeDelay(uint32_t miliseconds)&lt;BR /&gt;{&lt;BR /&gt; timeDelay_us(miliseconds * 1000);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void installTimeDelay()&lt;BR /&gt;{&lt;BR /&gt; /* Disable SysTick timer */&lt;BR /&gt; SysTick-&amp;gt;CTRL &amp;amp;= ~SysTick_CTRL_ENABLE_Msk;&lt;BR /&gt; /* Initialize Reload value to 1us */&lt;BR /&gt; SysTick-&amp;gt;LOAD = CORE_CLK_FREQ / 1000000;&lt;BR /&gt; /* Set clock source to processor clock */&lt;BR /&gt; SysTick-&amp;gt;CTRL |= SysTick_CTRL_CLKSOURCE_Msk;&lt;BR /&gt; /* Enable SysTick timer */&lt;BR /&gt; SysTick-&amp;gt;CTRL |= SysTick_CTRL_ENABLE_Msk;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;uint8_t Send_Byte(uint8_t byte_val){&lt;/P&gt;&lt;P&gt;uint8_t ucTemp;&lt;/P&gt;&lt;P&gt;tempBuff1[0] = byte_val;&lt;BR /&gt; xfer.txData = tempBuff1;&lt;BR /&gt; xfer.rxData = destBuff;&lt;BR /&gt; xfer.dataSize = 1;&lt;/P&gt;&lt;P&gt;// SPI_CS_Low();&lt;BR /&gt; xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &amp;amp;xfer);&lt;BR /&gt;// SPI_CS_High();&lt;/P&gt;&lt;P&gt;ucTemp = destBuff[0];&lt;BR /&gt; return ucTemp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;//uint8_t Send_Byte (uint8_t ucdata)&lt;BR /&gt;//{&lt;BR /&gt;// uint8_t ucTemp;&lt;BR /&gt;// while((SPI0_S &amp;amp; SPI_S_SPTEF_MASK) != SPI_S_SPTEF_MASK);&lt;BR /&gt;// SPI0_DL = ucdata;&lt;BR /&gt;//&lt;BR /&gt;// while((SPI0_S &amp;amp; SPI_S_SPRF_MASK) != SPI_S_SPRF_MASK);&lt;BR /&gt;// ucTemp = SPI0_DL;&lt;BR /&gt;// ucTemp = ucTemp;&lt;BR /&gt;// return ucTemp;&lt;BR /&gt;//}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//uint8_t Get_Byte(void)&lt;BR /&gt;//{&lt;BR /&gt;// uint8_t ucTemp;&lt;BR /&gt;//&lt;BR /&gt;// srcBuff[0] = regVal1;&lt;BR /&gt;// xfer.txData = srcBuff;&lt;BR /&gt;// xfer.rxData = destBuff;&lt;BR /&gt;// xfer.dataSize = sizeof(destBuff);&lt;BR /&gt;//&lt;BR /&gt;// xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &amp;amp;xfer);&lt;BR /&gt;//&lt;BR /&gt;// ucTemp = destBuff[0];&lt;BR /&gt;// return ucTemp;&lt;BR /&gt;//}&lt;/P&gt;&lt;P&gt;uint8_t MMCInit(){&lt;/P&gt;&lt;P&gt;uint8_t i = 0,k = 0,tmp = 0;&lt;BR /&gt; uint16_t cnt=0;&lt;BR /&gt; uint8_t buff[512];&lt;BR /&gt; uint8_t ucTemp;&lt;BR /&gt; timeDelay_us(5000);&lt;/P&gt;&lt;P&gt;for (i=0; i&amp;lt;0x0F; i++)&lt;BR /&gt; {&lt;BR /&gt; Send_Byte(0xFF); // send 72 clocks&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;do&lt;BR /&gt; {&lt;BR /&gt; tmp = MMCWriteCmd(CMD0,0x00,0x95); // CMD0&lt;BR /&gt; k++;&lt;BR /&gt; }while ((tmp != 1) &amp;amp;&amp;amp; (k &amp;lt; 200));&lt;/P&gt;&lt;P&gt;if(k == 0)&lt;BR /&gt; {&lt;BR /&gt; MMCCS(1); //cs pullup, disconnect&lt;BR /&gt; Send_Byte(0xFF);&lt;BR /&gt; printf("\n SD reset fail");&lt;BR /&gt; return 1;//&lt;BR /&gt; }&lt;BR /&gt; //get SD card version&lt;BR /&gt; tmp = MMCWriteCmd( CMD8,0x1AA,0x87 );&lt;BR /&gt; printf( "SD_CMD8 return %d........\n\n", tmp );&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// if(tmp == 1)// 2.0 card&lt;BR /&gt;// {&lt;BR /&gt;// cnt=0xffff;&lt;BR /&gt;//&lt;BR /&gt;// do&lt;BR /&gt;// {&lt;BR /&gt;// MMCWriteCmd( CMD55, 0, 0xff );&lt;BR /&gt;// tmp = MMCWriteCmd( CMD41,0x40000000, 0xff);//CMD41&lt;BR /&gt;// cnt--;&lt;BR /&gt;// } while ((tmp) &amp;amp;&amp;amp; (cnt));&lt;BR /&gt;// //Get OCR information&lt;BR /&gt;// tmp = MMCWriteCmd(CMD58, 0, 0 );&lt;BR /&gt;// if ( tmp != 0x00 )&lt;BR /&gt;// {&lt;BR /&gt;// MMCCS(1); //cs pullup, SD card disconnect&lt;BR /&gt;// printf( "\nSD_CMD58 return %d....\n", tmp );&lt;BR /&gt;// return 1;//&lt;BR /&gt;// }&lt;BR /&gt;//&lt;BR /&gt;// for ( i = 0; i &amp;lt; 4; i++ )&lt;BR /&gt;// {&lt;BR /&gt;// buff[ i ] = Get_Byte();&lt;BR /&gt;// }&lt;BR /&gt;// MMCCS(1);&lt;BR /&gt;// printf( "OCR return: %x %x %x %x....\n\n", buff[0],buff[1],buff[2],buff[3] );&lt;BR /&gt;//&lt;BR /&gt;// if ( buff[0] &amp;amp; 0x40 )&lt;BR /&gt;// {&lt;BR /&gt;// SD_Type = SD_TYPE_V2HC;&lt;BR /&gt;// printf( "card is V2.0 SDHC.....\n\n" );&lt;BR /&gt;// }&lt;BR /&gt;// else {&lt;BR /&gt;// SD_Type = SD_TYPE_V2;&lt;BR /&gt;// printf( "card is V2.0.....\n\n" );&lt;BR /&gt;// }&lt;BR /&gt;// while(MMCWriteCmd(CMD16,512,0xff)!=0);&lt;BR /&gt;// MMCWriteCmd(CMD9,0,0xff);&lt;BR /&gt;// }&lt;BR /&gt;// MMCCS(1);&lt;BR /&gt;// return 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;uint8_t sd_WaitRead( void )&lt;BR /&gt;{&lt;BR /&gt; uint32_t cnt = 0x00fffff;&lt;BR /&gt; uint8_t sta;&lt;BR /&gt; do&lt;BR /&gt; {&lt;BR /&gt; sta = Send_Byte( 0xff );;&lt;BR /&gt; if ( sta == 0xff ) //&lt;BR /&gt; {&lt;BR /&gt; return 0;&lt;BR /&gt; }&lt;BR /&gt; cnt--;&lt;BR /&gt; } while ( cnt );&lt;/P&gt;&lt;P&gt;return 1;&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;__inline static void sd_Disable_Select( void )&lt;BR /&gt;{&lt;BR /&gt; MMCCS(1);&lt;BR /&gt; Send_Byte( 0xff ); //&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;__inline static uint8_t sd_Enable_Select( void )&lt;BR /&gt;{&lt;BR /&gt; MMCCS(0);&lt;BR /&gt; if ( sd_WaitRead() == 0 ) // ??SD/MMC??&lt;BR /&gt; {&lt;BR /&gt; return 0;&lt;BR /&gt; }&lt;BR /&gt; sd_Disable_Select();&lt;/P&gt;&lt;P&gt;return 1;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;uint8_t MMCWriteCmd(uint8_t cmd, uint32_t arg, uint8_t crc )&lt;BR /&gt;{&lt;BR /&gt; uint16_t cnt=512;&lt;BR /&gt; uint8_t sta;&lt;/P&gt;&lt;P&gt;MMCCS(1); //SEL high&lt;BR /&gt; Send_Byte( 0xff ); //delay&lt;BR /&gt; MMCCS(0); //SEL low&lt;/P&gt;&lt;P&gt;if (sd_Enable_Select())&lt;BR /&gt; {&lt;BR /&gt; return 0xff;&lt;BR /&gt; }&lt;BR /&gt; //40 00 00 00 00 95 for CMD0&lt;BR /&gt; //48 00 00 01 AA 0F for CMD8&lt;BR /&gt; //7A 00 00 00 00 75 for CMD58&lt;/P&gt;&lt;P&gt;startCMD[0] = cmd | 0x40 ;&lt;BR /&gt; startCMD[1] = arg&amp;gt;&amp;gt;24;&lt;BR /&gt; startCMD[2] = arg&amp;gt;&amp;gt;16;&lt;BR /&gt; startCMD[3] = arg&amp;gt;&amp;gt;8;&lt;BR /&gt; startCMD[4] = arg;&lt;BR /&gt; startCMD[5] = crc;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; xfer.txData = startCMD;&lt;BR /&gt; xfer.rxData = endBuff;&lt;BR /&gt; xfer.dataSize = 7;//sizeof(endBuff); 6 bytes and one more&lt;BR /&gt; SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &amp;amp;xfer);&lt;/P&gt;&lt;P&gt;// Send_Byte( cmd | 0x40 );&lt;BR /&gt;// Send_Byte( (uint8_t)(arg&amp;gt;&amp;gt;24) );&lt;BR /&gt;// Send_Byte( (uint8_t)(arg&amp;gt;&amp;gt;16) );&lt;BR /&gt;// Send_Byte( (uint8_t)(arg&amp;gt;&amp;gt;8) );&lt;BR /&gt;// Send_Byte( (uint8_t)(arg) );&lt;BR /&gt;// Send_Byte( crc ); // CRC&lt;/P&gt;&lt;P&gt;do&lt;BR /&gt; {&lt;BR /&gt; sta = Send_Byte(0xff);&lt;BR /&gt; cnt--;&lt;BR /&gt; } while ( (cnt)&amp;amp;&amp;amp;(sta==0xff) );&lt;/P&gt;&lt;P&gt;return sta;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void MMCCS(uint8_t cs)&lt;BR /&gt;{&lt;BR /&gt; if (cs == 1)&lt;BR /&gt; {&lt;BR /&gt; SPI_CS_High(); // SS=1&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt; SPI_CS_Low(); // SS=0&lt;BR /&gt; }&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;int main(void)&lt;BR /&gt;{&lt;BR /&gt; uint16_t i,j;&lt;BR /&gt; // FATFS fs;&lt;BR /&gt; FRESULT fr;&lt;BR /&gt; FIL fil;&lt;BR /&gt; UINT bw;&lt;BR /&gt; char file_name1[12]="Test.csv";&lt;BR /&gt; char file_name2[12]="Test.txt";&lt;BR /&gt;// System_init();&lt;BR /&gt;// spiInit(SPI0_BASE_PTR , Master);&lt;/P&gt;&lt;P&gt;CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);&lt;BR /&gt; CLOCK_AttachClk(kFRO12M_to_FLEXCOMM5);&lt;BR /&gt; RESET_PeripheralReset(kFC5_RST_SHIFT_RSTn);&lt;BR /&gt; BOARD_InitPins();&lt;BR /&gt; BOARD_BootClockFROHF48M();&lt;BR /&gt; BOARD_InitDebugConsole();&lt;BR /&gt; GPIO_Configuration();&lt;BR /&gt; installTimeDelay();&lt;/P&gt;&lt;P&gt;SPI_MasterGetDefaultConfig(&amp;amp;userConfig);&lt;BR /&gt; srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ_LOW;//EXAMPLE_SPI_MASTER_CLK_FREQ;&lt;BR /&gt; //masterConfig.sselNum = (spi_ssel_t)EXAMPLE_SPI_SSEL;&lt;BR /&gt; SPI_MasterInit(EXAMPLE_SPI_MASTER, &amp;amp;userConfig, srcFreq);&lt;/P&gt;&lt;P&gt;while(1){&lt;BR /&gt; MMCInit();&lt;BR /&gt; //MMCInit();&lt;BR /&gt; for(uint32_t i = 100000; i != 0; i--);&lt;BR /&gt; //timeDelay(3000);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;// fr= f_mount(&amp;amp;fs,file_name1,0);&lt;BR /&gt;// if(fr)&lt;BR /&gt;// {&lt;BR /&gt;// printf("\nError mounting file system\r\n");&lt;BR /&gt;// for(;;){}&lt;BR /&gt;// }&lt;BR /&gt;// // fr = f_open(&amp;amp;fil, file_name1, FA_WRITE | FA_OPEN_ALWAYS);//create csv file&lt;BR /&gt;// if(fr)&lt;BR /&gt;// {&lt;BR /&gt;// printf("\nError opening text file\r\n");&lt;BR /&gt;// for(;;){}&lt;BR /&gt;// }&lt;BR /&gt;// fr = f_write(&amp;amp;fil, "Test1 ,Test2 ,Test3 ,Test4 \r\n", 29, &amp;amp;bw); //write data to the excel file&lt;BR /&gt;// if(fr)&lt;BR /&gt;// {&lt;BR /&gt;// printf("\nError write text file\r\n");&lt;BR /&gt;// for(;;){}&lt;BR /&gt;// }&lt;BR /&gt;// fr = f_close(&amp;amp;fil);&lt;BR /&gt;// if(fr)&lt;BR /&gt;// {&lt;BR /&gt;// printf("\nError close text file\r\n");&lt;BR /&gt;// for(;;){}&lt;BR /&gt;// }&lt;BR /&gt;// fr= f_mount(&amp;amp;fs,file_name2,0);&lt;BR /&gt;// if(fr)&lt;BR /&gt;// {&lt;BR /&gt;// printf("\nError mounting file system\r\n");&lt;BR /&gt;// for(;;){}&lt;BR /&gt;// }&lt;BR /&gt;// fr = f_open(&amp;amp;fil, file_name2, FA_WRITE | FA_OPEN_ALWAYS);//create txt file&lt;BR /&gt;// if(fr)&lt;BR /&gt;// {&lt;BR /&gt;// printf("\nError opening text file\r\n");&lt;BR /&gt;// for(;;){}&lt;BR /&gt;// }&lt;BR /&gt;// fr = f_write(&amp;amp;fil, "Test1 ,Test2 ,Test3 ,Test4 \r\n", 29, &amp;amp;bw); //write data to the txt file&lt;BR /&gt;// if(fr)&lt;BR /&gt;// {&lt;BR /&gt;// printf("\nError write text file\r\n");&lt;BR /&gt;// for(;;){}&lt;BR /&gt;// }&lt;BR /&gt;// fr = f_close(&amp;amp;fil);&lt;BR /&gt;// if(fr)&lt;BR /&gt;// {&lt;BR /&gt;// printf("\nError close text file\r\n");&lt;BR /&gt;// for(;;){}&lt;BR /&gt;// }&lt;BR /&gt;// while(1)&lt;BR /&gt;// {&lt;BR /&gt;// for(i=0;i&amp;lt;10;i++) for(j=0;j&amp;lt;65535;j++);&lt;BR /&gt;// printf("\ntest_sd\n");//&lt;BR /&gt;// }&lt;BR /&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Apr 2018 10:03:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726612#M29376</guid>
      <dc:creator>puddletowntom</dc:creator>
      <dc:date>2018-04-16T10:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Talk to an SD card via SPI?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726613#M29377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A few thoughts having written a SD card interface in assembler on an LPC1517:&lt;/P&gt;&lt;P&gt;I can't exactly tell from the oscilloscope trace how fast the 80 pulses are, but they should be no quicker than 400kHz. I think you might be a bit close to the limit.&lt;/P&gt;&lt;P&gt;The pulses don't have to be evenly spaced. I send five 16-bit words of 0xFFFF via the SPI interface, and I use 200kHz until it responds to CMD0 then speed it up.&lt;/P&gt;&lt;P&gt;A reply of 9 from the card = CRC check fault.&lt;/P&gt;&lt;P&gt;I'm just wondering if&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;MMCWriteCmd( CMD8,0x1AA,0x87 ) is correct. Does your MMCWriteCmd function write 8-bit values? If so, you've got a 9-bit value in there, which is probably getting truncated to 8 bits.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;You've also got&amp;nbsp;&lt;SPAN&gt;//48 00 00 01 AA 0F for CMD8, when the CRC should be 0x87.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;I send CMD 8 as 0x4800, 0x0001, 0xAA87&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;It should respond with 0x01, followed by two 16-bit words which echo the command.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;&lt;SPAN&gt;Another thing, the spec says you should send 8 extra clock pulses at the end of each command for it to finish its internal workings.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Apr 2018 20:03:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726613#M29377</guid>
      <dc:creator>ianbenton</dc:creator>
      <dc:date>2018-04-19T20:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: Talk to an SD card via SPI?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726614#M29378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for the late response. I was busy with other things and had parked this work aside. So slowing down the clock speed for the initialisation worked. This was something I forgot to do before. I was able to get the correct responses back for the SD commands. I m able to read and write to the SD card also so I can use it as a basic data logger, however still working on integration with the FATFS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the help.&lt;/P&gt;&lt;P&gt;Ronan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 May 2018 12:04:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Talk-to-an-SD-card-via-SPI/m-p/726614#M29378</guid>
      <dc:creator>puddletowntom</dc:creator>
      <dc:date>2018-05-23T12:04:30Z</dc:date>
    </item>
  </channel>
</rss>

