Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Write Data from UART to MMC card ? where is my problem ?

Status
Not open for further replies.

zenpar

Newbie level 3
Joined
Jun 8, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,311
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 ..
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:

One issue maybe that ASCII 10 or 0x0A is actually a LineFeed (LF) or NewLine (NL), while a Carriage Return CR is 13 or 0x0D.

Depending on your terminal emulation program, the PIC may or may not ever receive the LF or NL.

Are you sure the Carriage Return is indeed being detected? And the data actually being written to the SD Card?

You may want to automatically write the buffer when the index reaches 10 as a safe guard. Or send a message back to the PC when a write to SD is in progress.

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top