That's IMO putting the cart before the horse.Owais wrote:My main goal at this point was to just write a raw data into an already formatted SD card and then read that data back
It's prudent to get the (non-destructive) read operational first, especially when a non-removable medium is used.
Once read capability is reliable, then attempt (destructive) write operations.
The microcontroller datasheet only provides you with a description of the host controller.Owais wrote:... the read write operation given in the datasheet,
The MCI interface is actually a bus interface to intelligent peripherals.
You need to also reference the SDcard spec to which jharley has provided a link.
The SDcard spec describes the modes of the host and the states of the SDcard that can be used to create state machines in the device driver for the host side and for each socket/card.
No, you cannot write just "a byte".Owais wrote: its just that if I give a data lets say a byte and try to write it randomly anywhere in the SD card would this work?
As I already wrote, the SDcard is a block device.
BTW although data transfers are always for a block, the address of that block depends on the SDcard capacity.
SDSC (i.e. 2GB card or smaller) uses a 32-bit byte address that should be block aligned.
SDHC and SDXC use a 32-bit block address.
Card addressing is implemented using a session address, assigned to the card during the initialization phase.Owais wrote: Also the SD card publishes a RCA(Relative Card Address) what is the purpose of that is it somehow used in writing or reading the very first data to the SD card?
This is a mechanism for the host to reliably handle removable media.
A newly inserted SDcard will be in the "uninitialized" state and have a RCA of zero, which is otherwise invalid.
During the "card identification mode" the SDcard will generate its RCA. The host needs to verify that this SDcard's RCA is unique compared to any other (when there are multiple sockets).
The RDA is then used to select a SDcard when issuing commands during the "data transfer mode".
If the SDcard is removed or replaced, then there will no longer be a response to that RCA and a newly inserted SDcard will not be inadvertently written or read.