rmarkespanto
Junior Member level 1
- Joined
- Jan 30, 2012
- Messages
- 18
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,293
- Location
- phillippines
- Activity points
- 1,401
/*********************SECURE DIGITAL CARD PROJECT************************/
/************************************************************************/
/*
CS is Connected to RC2
CLK is Connected to RC3
DO is Connected to RC4
DI is Connected to RC5
The program reads the SD card CID register parameters and sends it to a PC via the serial interface.
This process is repeated at every 10 seconds.
*/
/*************************** MMC MODULE CONNECTION*************************/
sfr sbit Mmc_Chip_Select at RC2_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISC2_bit;
/**************************************************************************/
/***********************Function For New Line******************************/
void NewLine()
{
UART1_Write(10); //Line Feed
UART1_Write(13); //Carriage Return
}
/**************************************************************************/
/**********************MAIN PROGRAM STARTS FROM HERE***********************/
unsigned char error, CID[16]; //CID means Card Identification Register
unsigned char msg[] = "SD Card CID Register";
unsigned int i;
unsigned short x;
unsigned char Data1[512],Data2[512]; //These Variables are used to Store and Receive Data in SD Card
void main()
{
//Configure the Serial Port
UART1_Init(9600); //Set Baud Rate of 2400bps
//Initialize the Secure Digital Card
//Set SPI1 module to master mode, clock = Fosc/16, data sampled at the middle of interval,
//clock idle state low and data transmitted at low to high edge:
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
//Initialize the Secure Digital Card Bus
//And Check Whether it gets Initialized or Not
//If Not then try again and Again
// memory_card_not_detected:
while(Mmc_Init() != 0)
{
NewLine();
UART1_Write_Text("Memory Card Not Detected");
}
NewLine();
UART1_Write_Text("Memory Card Detected Successfully!!");
//If Memory Card Detected Successfully
NewLine();
UART1_Write_Text(msg);
while(Mmc_Read_CID(CID) != 0)
{
NewLine();
UART1_Write_Text("CID Value Not Found");
NewLine();
}
NewLine();
UART1_Write_Text("CID Values are Obtained");
NewLine();
//Now we will loads sector 10 of the SD card with character "A".
//The contents of sector 10 is then read and sent to the UART,
//displaying 512 "A" characters on the PC display.
UART1_Write_Text("Now Time To Write Some Data in the SD Card");
for(i=0;i<20;i++)
{
NewLine();
}
//The Above For Loop Clear the Hyper-Terminal Screen
//Now Fill the Buffer with Character "A"
for(i=0;i<512;i++)
{
Data1[i] = "A";
}
//After this the Data1 buffer gets Filled with "A" Character
//Now write this buffer to SD Card Sector
x = Mmc_Write_Sector(10,Data1); //Writing Data to 10th Sector
//We Can Check Here whether Writing was Successful or not by Monitoring the Value x
if(x == 0)
{
UART1_Write_Text("Write Successfull");
Newline();
}
//Now Read The Data From Sector-10 of SD Card
x = Mmc_Read_Sector(10,Data2); //Read data From Sector-10 of SD card and Store the Result in Data2
if(x == 0)
{
UART1_Write_Text("Read Successfull");
Newline();
}
//Display the Result on Hyper-Terminal
for(i=0;i<10;i++)
{
UART1_Write(Data2[i]);
}
while(1); //Stop Code Here for Debugging Purpose*/
}
what if the pin for rx and sdo are in only one pin... do you have a solution for this bro???
can you please explain to me, how data from sd card have been put on serial port, and vice versa... thanks a lot...
do you have any tutorial for theory of sd card, or how it is function.. i have many research, but it is so hard to understand,You have to read data from Memory Sectors...
I think first of all you have to learn basics of SD and MMC Card and SPI...
while(total_number_of_package!=0)
{
unsigned char image_data[];
i=0;
while(i<256)
{
if(UART_Data_Ready()==1)
{
image_data[i]=UART_Read(); \\1 byte every loop
}
}
}
unsigned char x,image_data[256];
unsigned int i;
for(i=0;i<256;i++)
{
if(UART1_Data_Ready() == 1)
{
image_data[i] = UART1_Read();
}
}
x = Mmc_Write_Sector(10,image_data); //Writing Data to 10th Sector
//We Can Check Here whether Writing was Successful or not by Monitoring the Value x
if(x == 0)
{
UART1_Write_Text("Write Successfull");
Newline();
}
Arun Sharma
But i want to ask a question from you...
How will you know whether the Image Written by you is Properly Written..
I mean to say that do you have any display device.. to show the Image when extracted from the SD Card..
Or you will read it in your PC or any other device having a Memory Card Slot..
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?