FatFs file library to create file system on SD card using PIC18f26k80

Discussion in 'Embedded Systems and Microcontrollers' started by Sangam Singh, Jul 6, 2015.

  1. Sangam Singh

    Thread Starter New Member

    Jun 23, 2015
    9
    0
    i am using PIC18f26k80 to create file system on a micro SD card using the FatFs library available here. I moved the .c and .h files to the working directory and implemented a sample code to read a text file and display it, available here. But i am getting error with the code.

    This is my code:

    Code (Text):
    1. // Header Files
    2. #include <xc.h>
    3. #include <p18cxxx.h>
    4. #include <stdio.h>
    5. #include <stdlib.h>
    6. #include <plib/pconfig.h>
    7. #include "ffconf.h"
    8. #include "ff.h"
    9. #include "diskio.h"
    10. #include "integer.h"
    11.  
    12. // PIC18F25K80 Configuration Bit Settings
    13.  
    14. // #pragma config statements should precede project file includes.
    15. // Use project enums instead of #define for ON and OFF.
    16.  
    17. // CONFIG1L
    18. #pragma config RETEN = ON           // VREG Sleep Enable bit (Ultra low-power regulator is Enabled (Controlled by SRETEN bit))
    19. #pragma config INTOSCSEL = HIGH     // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power mode during Sleep)
    20. #pragma config SOSCSEL = HIGH       // SOSC Power Selection and mode Configuration bits (High Power SOSC circuit selected)
    21. #pragma config XINST = OFF          // Extended Instruction Set (Disabled)
    22.  
    23. // CONFIG1H
    24. #pragma config FOSC = INTIO1        // Oscillator (Internal RC oscillator, CLKOUT function on OSC2)
    25. #pragma config PLLCFG = ON          // PLL x4 Enable bit (Enabled)
    26. #pragma config FCMEN = OFF          // Fail-Safe Clock Monitor (Disabled)
    27. #pragma config IESO = OFF           // Internal External Oscillator Switch Over Mode (Disabled)
    28.  
    29. // CONFIG2L
    30. #pragma config PWRTEN = OFF         // Power Up Timer (Disabled)
    31. #pragma config BOREN = OFF          // Brown Out Detect (Disabled in hardware, SBOREN disabled)
    32. #pragma config BORV = 3             // Brown-out Reset Voltage bits (1.8V)
    33. #pragma config BORPWR = ZPBORMV     // BORMV Power level (ZPBORMV instead of BORMV is selected)
    34.  
    35. // CONFIG2H
    36. #pragma config WDTEN = OFF          // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
    37. #pragma config WDTPS = 1048576      // Watchdog Postscaler (1:1048576)
    38.  
    39. // CONFIG3H
    40. #pragma config CANMX = PORTB        // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and RB3, respectively)
    41. #pragma config MSSPMSK = MSK7       // MSSP address masking (7 Bit address masking mode)
    42. #pragma config MCLRE = ON           // Master Clear Enable (MCLR Enabled, RE3 Disabled)
    43.  
    44. // CONFIG4L
    45. #pragma config STVREN = ON          // Stack Overflow Reset (Enabled)
    46. #pragma config BBSIZ = BB2K         // Boot Block Size (2K word Boot Block size)
    47.  
    48. // CONFIG5L
    49. #pragma config CP0 = OFF            // Code Protect 00800-01FFF (Disabled)
    50. #pragma config CP1 = OFF            // Code Protect 02000-03FFF (Disabled)
    51. #pragma config CP2 = OFF            // Code Protect 04000-05FFF (Disabled)
    52. #pragma config CP3 = OFF            // Code Protect 06000-07FFF (Disabled)
    53.  
    54. // CONFIG5H
    55. #pragma config CPB = OFF            // Code Protect Boot (Disabled)
    56. #pragma config CPD = OFF            // Data EE Read Protect (Disabled)
    57.  
    58. // CONFIG6L
    59. #pragma config WRT0 = OFF           // Table Write Protect 00800-03FFF (Disabled)
    60. #pragma config WRT1 = OFF           // Table Write Protect 04000-07FFF (Disabled)
    61. #pragma config WRT2 = OFF           // Table Write Protect 08000-0BFFF (Disabled)
    62. #pragma config WRT3 = OFF           // Table Write Protect 0C000-0FFFF (Disabled)
    63.  
    64. // CONFIG6H
    65. #pragma config WRTC = OFF           // Config. Write Protect (Disabled)
    66. #pragma config WRTB = OFF           // Table Write Protect Boot (Disabled)
    67. #pragma config WRTD = OFF           // Data EE Write Protect (Disabled)
    68.  
    69. // CONFIG7L
    70. #pragma config EBTR0 = OFF          // Table Read Protect 00800-03FFF (Disabled)
    71. #pragma config EBTR1 = OFF          // Table Read Protect 04000-07FFF (Disabled)
    72. #pragma config EBTR2 = OFF          // Table Read Protect 08000-0BFFF (Disabled)
    73. #pragma config EBTR3 = OFF          // Table Read Protect 0C000-0FFFF (Disabled)
    74.  
    75. // CONFIG7H
    76. #pragma config EBTRB = OFF          // Table Read Protect Boot (Disabled)
    77.  
    78. /*
    79. *
    80. */
    81. FATFS FatFs;   /* Work area (file system object) for logical drive */
    82.  
    83. int main (void)
    84. {
    85.     FIL file;       /* File object */
    86.     char line[82]; /* Line buffer */
    87.     FRESULT fr;    /* FatFs return code */
    88.  
    89.  
    90.     /* Register work area to the default drive */
    91.     f_mount(&FatFs," ", 0);
    92.  
    93.     /* Open a text file */
    94.     fr = f_open(&file,"message.txt", FA_READ);
    95.     if (fr) return (int)fr;
    96.  
    97.     /* Read all lines and display it */
    98.     while (f_gets(line,sizeof line, &file))
    99.         printf(line);
    100.  
    101.     /* Close the file */
    102.     f_close(&file);
    103.  
    104.     return 0;
    105. }
    106.  
    107.  
    And this is the error that I am getting:

    Code (Text):
    1.  main.c:91: error: (1466) registers unavailable for code generation of this expression
    2.     main.c:94: error: (1466) registers unavailable for code generation of this expression
    3.     main.c:98: error: (1466) registers unavailable for code generation of this expression
    4.     main.c:102: error: (1466) registers unavailable for code generation of this expression
    How shall I change my code to properly write/read files on the SD Card ?
     
Loading...