zenpar
Newbie level 3
Hi All
I use PIC18f4520 8MHZ // Mikroc compiler ..
I Write simple code that will read data from UART until it find 10 "CR" and thin send this data to SD card ... now my issue is that ,
when i write to SD card i receive scramble data !!!!!! but i write normal data to SD card it work fine with correct data .. where is my problem?
when i use this function to write normal data to sd card .. it work fine and i receive correct data ..
this code work fine and i read the data from my PC ..
Now with this code .. it should collect the data from the UART until we see "10" or "CR" from UART .. thin write collect data to SD card ..
i receive scramble data .. !!!!1:------(
i try every thing but without any help ... please any advice can help me out in this issue ..
regards and thanks in advance
I use PIC18f4520 8MHZ // Mikroc compiler ..
I Write simple code that will read data from UART until it find 10 "CR" and thin send this data to SD card ... now my issue is that ,
when i write to SD card i receive scramble data !!!!!! but i write normal data to SD card it work fine with correct data .. where is my problem?
when i use this function to write normal data to sd card .. it work fine and i receive correct data ..
this code work fine and i read the data from my PC ..
Code:
void M_Create_New_File() {
Mmc_Fat_Assign("TEST.txt", 0xA0); // Find existing file or create a new one
Mmc_Fat_Rewrite(); // To clear file and start with new data
Mmc_Fat_Write("www.edaboard.com", 15); // write data to the assigned file
}
Now with this code .. it should collect the data from the UART until we see "10" or "CR" from UART .. thin write collect data to SD card ..
i receive scramble data .. !!!!1:------(
Code:
sbit Mmc_Chip_Select at LATC0_bit; // for writing to output pin always use latch (PIC18 family)
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
unsigned char tmp;
char data1[10];
unsigned char times;
unsigned char found1;
void M_Create_New_File() {
Mmc_Fat_Set_File_Date(2010, 4, 19, 9, 0, 0); // Set file date & time info
Mmc_Fat_Assign("TEST.txt", 0xA0); // Find existing file or create a new one
Mmc_Fat_Rewrite();
UART1_Write('.');
for(found1=0;found1<=times;found1++)
{
Mmc_Fat_Write(data1[found1],1); // write data to the assigned file
}
}
void main()
{
osccon=0b01110000;
ADCON1 |= 0x0F; // Configure AN pins as digital
CMCON |= 7; // Turn off comparators
UART1_Init(9600);
Delay_ms(10);
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
UART1_Write_Text("PIC-Started1"); // PIC present report
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
if (Mmc_Fat_Init() == 0) { // Mean that we have communcation
UART1_Write_Text("YES");
times = 0;
found1=0; // Array Pointer ..
while(1){
if (UART1_Data_Ready())
tmp = UART1_Read();
{
if (tmp=10) // If we find Enter ...
{
M_Create_New_File(); // Write to SD card
}
else // collect data
{
data1[found1]=tmp;
found1++;
times++;
}
}
}
}
}
i try every thing but without any help ... please any advice can help me out in this issue ..
regards and thanks in advance
Last edited: