Linker error using sd card and pic18f458

Discussion in 'Embedded Systems and Microcontrollers' started by Bushratariq, Jul 7, 2014.

  1. Bushratariq

    Thread Starter New Member

    May 15, 2014
    13
    0
    hey everyone!

    I am trying to write/read to SD card using PIC18f458. I am using microchip software and all the libraries that supports writing to sd cards.
    When i compile i get the error

    '.code_FSIo_O' can not fit the section. Section '.code_FSIo_O' length = 0x0000e84c

    Can anyone please guide me? What is this error about?
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    It's about memory size. The way you have it now you are asking for more memory then exists. It may be the case where you have memory, just not in one segment as your code is expecting but SD apps take a huge amount of RAM and ROM.

    I cannot get more specific without seeing and playing with the entire project.
     
  3. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,399
    497
    "That's usually what you see when you overflow your Program Space. You run out of space and it can't fit in some of the later stuff like the libraries.
    Check your .map file. The maximum you can get is about 90% of total program space.

    For a quick test you can turn on the optimizers if you haven't already and it should fit in (for now anyways)."
    http://www.chiefdelphi.com/forums/showpost.php?p=320929&postcount=2
     
  4. Bushratariq

    Thread Starter New Member

    May 15, 2014
    13
    0
    Thanks everyone. i changed my pic to 64k memory(i.e. pic18f4680) and was able to compile the code.

    Now i am facing another problem. i am running a simple code that is supposed to create a txt file on sd card and write a line in it. My code starts from initializing command. the card sends some data on its output pin in response which makes me think the card has initialized. the other commands are then to write to the sd card. when i connect sd card to computer , the card is empty.
    I dont know whats wrong? can anyone please help???
    My code is as follows

    Code ( (Unknown Language)):
    1.  
    2. void main(void)
    3. {
    4. FSFILE *MyFile;
    5. unsigned char txt[ ]="This is a TEXT message";
    6. //
    7. // Initialize the SD card routines
    8. //
    9. FSInit( );
    10. //
    11. // Create a new file called MESSAGE.TXT
    12. //
    13. MyFile = FSfopenpgm("MESSAGE.TXT", "w+");
    14. //
    15. // Write message to the file
    16. //
    17. FSfwrite(txt, 1, 22, MyFile);
    18. // Close the file
    19. //
    20. FSfclose(MyFile);
    21. while(1);
    22. }
    23.  
     
    Last edited by a moderator: Aug 15, 2014
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    Is the SD card formatted?

    Did you check the return values of the function calls?
     
  6. Bushratariq

    Thread Starter New Member

    May 15, 2014
    13
    0
    thank you for your reply. i am working on this for the first time.i have no idea how to check return values. Can you please guide me??
    Also i formatted the card using laptop and then i connected it to the circuit.
     
  7. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    write some files on it + try to read the directory.
     
  8. Bushratariq

    Thread Starter New Member

    May 15, 2014
    13
    0
    thank you everyone. i checked the return value. and yes the card does not initialize. what do i do now??? what can be the possible reasons for this???
    please help.
    Just for information i am using 8gb sd card. if it has anything to do with it. My code now is as follows
    My code is as follows

    Code ( (Unknown Language)):
    1.  
    2. void delay (unsigned int k)
    3. for (i=0;i<=k;i++)
    4. {
    5. ;
    6. }
    7. void main(void)
    8. {
    9. FSFILE *MyFile;
    10. unsigned char txt[ ]="This is a TEXT message";
    11. TRISB=0;
    12. //
    13. // Initialize the SD card routines
    14. //
    15. FSInit( );
    16. if (FSInit()!=TRUE)
    17. {PORTB=0xFF;
    18. delay(10000);
    19. PORTB=0x0;
    20. delay(10000);
    21. }
    22. //
    23. // Create a new file called MESSAGE.TXT
    24. //
    25. MyFile = FSfopenpgm("MESSAGE.TXT", "w+");
    26. //
    27. // Write message to the file
    28. //
    29. FSfwrite(txt, 1, 22, MyFile);
    30. // Close the file
    31. //
    32. FSfclose(MyFile);
    33. while(1);
    34. }
    35.  
    When i run the code, the portb leds blink. which means the sd card does not initialize.
     
    Last edited by a moderator: Aug 19, 2014
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    While it is probably acceptable to FSInit the card twice in a row, take the first one out anyway just to rule it out.

    After that it is time to post your schematic.

    Pictures of the build may also be useful.
     
  10. Bushratariq

    Thread Starter New Member

    May 15, 2014
    13
    0
    I am posting my code and diagram. Please have a look at it. I am still not able to initialize the sd card. And i have absolutely no idea why.
     
    • BP.zip
      File size:
      13 KB
      Views:
      13
  11. Bushratariq

    Thread Starter New Member

    May 15, 2014
    13
    0
    The attachment contains the libraries i used for my project.
     
    • BP1.zip
      File size:
      107.8 KB
      Views:
      12
  12. Bushratariq

    Thread Starter New Member

    May 15, 2014
    13
    0
    hey everyone. please help me. i have posted my code and schematics. please have a look at it. and help me what am doing wrong. why my card is not initializing????
     
Loading...