Hi,
I am trying to write to a 512 MB Kingston SD card using the MSP430G2231 interfacing the card via SPI.
The code I use is the slaa281b provided by TI. Now the card initializes correctly and I can write to the card
but when I look at it in the Hex editor I can´t find the data.
The MSP430G2231 has just 128 bytes of RAM so I defined a 8 bytes buffer and not like it´s done in the code
examples a 512 bytes buffer.
To write a block of 512 bytes I programmed a loop which sends the buffer 64 times to the card.
Could it be a problem that the buffer isn´t written at once ??
Or can anyone think of another problem ??
See my answer in the other SD card thread for your exact same question.
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.
Hi Jens,
by now I managed to initialize the SD card with ACMD41.
To wait a bit longer for the reponse I added a delay_cycles function.
//Send one byte via SPIunsigned short spiSendByte(const unsigned short data){ while (SPITXREADY ==0); // wait while not ready for TX SPI_SEND(data); // write while (SPIRXREADY ==0); // wait for RX buffer (full) __delay_cycles(1500); return (SPIRXBUF);}
The SPIRXREADY I found out is set to 1 by a define and never unset so the code would never wait for
the buffer to be full I guess.
So when I send CMD0 and let it run I get 0x01.
Then I send CMD55 and wait for the reponse and then send ACMD41 and wait for the response.
This is going on until the card reponds with 0x00 what it does after sending the CMD55, ACMD41
sequence the second time.
So the mos recent success is that the card initializes now correctly and I even don´t have to single
step through the code.
But I still can`t write anything to the card. The commands for setting blocklength and writing are
responded correct but the data isn´t on the card when I look at it in my hex editor.
MaxEBut I still can`t write anything to the card. The commands for setting blocklength and writing are responded correct but the data isn´t on the card when I look at it in my hex editor.
First, if the card is no SDHC/SDXC card, the address is a byte address. So an address of "0x00000200" writes to segment 1, not segment 512. Also, Windows (or whatever OS your hex editor runs on) may fool you about the sector number by adding an offset for some OS-handled formatting stuff in the first sector, depending on how the card has been formatted.
Ok so if I use the SDWriteBlock like this :
SDWriteBlock(512ul,512ul,buffer);
It should write to sector one shouldn´t it ??
Now I formated the card with FAT16. My OS is Windows 7.
Do you have a guess at which offset I can expect the data I wanted to write??
It should be one sector full of ones.
MaxEIt should write to sector one shouldn´t it ??
MaxENow I formated the card with FAT16. My OS is Windows 7.
Better first format the card, then write to a sector that's definitely in the data area. (don't ask me where. It's been a while since I looked at disk sectors for unerasing data)
Jens-Michael Gross Better first format the card, then write to a sector that's definitely in the data area. (don't ask me where. It's been a while since I looked at disk sectors for unerasing data)
Sorry that I told this a bit confusingly but I actually formated the SD Card before I wrote to it.
Now I analyzed the whole procedure with a logic analyzer and everything seems to work correct.
Even I read out the CSD register after the transaction as told by the specs and there are no errors.
So I guess the data is successfully written to the card. Now the only problem is to find it !!
Yiiiiiiiiihaaaaaaaaa,
it works.
Just experimented a lot with the adressoffset and wrote 1000 sectors on the card.
Now I found my data.
Many thanks to you Jens and to Mark Green. You guys gave me such a strong support in the
last few weeks and guided me to success.
MaxEit works.
MaxENow I found my data.
I wrote beginning in sector 500 up to sector 1500 and it appeared on the card under windows
beginning at sector 265. The next thing to do is to implement some functions to write to the fat16
so when I read out the fat16 boot record maybe I can make more of a guess about
the adressoffset.
Wow. 235 sectors offset. I wonder what Windows stores in these sectors.Or did the hex editor access 'clusters' rather than raw sectors? Then of course this offset contains the FAT.
There are one or two free FAT file system available for the MSP430. All they need are the low-level functions that read and write a sector - which you now have.The links are somewhere her ein the forum (I don't remember - I downlaoded the code but lsot the link)