Helpful ReplyHot!FatFs library for sd card interace with PIC24FJ128GA010

Author
yo123
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2017/04/19 09:52:08
  • Location: 0
  • Status: offline
2019/01/10 07:43:53 (permalink)
0

FatFs library for sd card interace with PIC24FJ128GA010

hi,
i want to interface sd card with PIC24FJ128GA010 using FatFs library. i search some tutorial on google and i found that it is easy to configure SPI using MCC.  below function  is generated using MCC
clock=> FRC with FCY=8MHz
SPI1=>SPI1_Initialzation()   //125KHz
           SPI1_OPEN()     //2MHz this i inserted my own
void SPI1_Exchange( uint8_t *pTransmitData, uint8_t *pReceiveData )
{

    while( SPI1STATbits.SPITBF == true )
    {

    }

    SPI1BUF = *((uint8_t*)pTransmitData);

    while ( SPI1STATbits.SPIRBF == true);

    *((uint8_t*)pReceiveData) = SPI1BUF;

}

 
void SPI1_OPEN(void)
{
   // MSTEN Master; DISSDO disabled; PPRE 16:1; SPRE 2:1; MODE16 disabled; SMP Middle; DISSCK disabled; CKP Idle:Low, Active:High; CKE Active to Idle;
    SPI1CON1 = 0x13B;
    // SPIBEN enabled; SPIFPOL disabled; SPIFE disabled;
    SPI1CON2 = 0x00;
    // SPITBF disabled; SISEL SPI_INT_SPIRBF; SPIRBF disabled; SPIROV disabled; SPIEN enabled; SRXMPT disabled; SRMPT disabled; SPISIDL disabled; SPIBEC disabled;
    SPI1STAT = 0x800C;
}

 
to  disabled the Enhanced buffer mode
 after that  i checked the SPI using debugger , now i can see  that write function correct.
but did not check about  reading the SPI, please go through the SPI write function and correct me if am wrong for reading purpose.
uint8_t SPI1_Exchange8bit( uint8_t data )
{
    uint8_t receiveData;
    
    SPI1_Exchange(&data, &receiveData);

    return (receiveData);
}

 
after that i want to insert the FATFS function which attached below.
please suggest me, if  i have to edit anything in below file because i tried number of times but did not get
output.
thanking you
#1
yo123
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2017/04/19 09:52:08
  • Location: 0
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/11 07:19:56 (permalink)
0
hi all,
 so, when tried to mount the SD card , i got the error "FR_NOT_READY".
after searching, it may because of following reason.
  • No medium in the drive.
  • Wrong lower layer implementation.
  • Wrong hardware configuration.
  • The storage device has broken.
why this is happening?????
the card is 4GB with FAT32 formatted and the card adapter is having 3.3 voltage shifter.
please suggest your experience to solve this problem.
thanking you.
#2
Aussie Susan
Super Member
  • Total Posts : 3518
  • Reward points : 0
  • Joined: 2008/08/18 22:20:40
  • Location: Melbourne, Australia
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/13 18:13:02 (permalink)
0
As you have not got an answer form someone who actually knows the answer (yet)...
I seem to recall that FAT16 is about the most advanced format you can use. Try reformatting the SD card to FAT16 and see if that works.
Susan
#3
yo123
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2017/04/19 09:52:08
  • Location: 0
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/21 06:33:21 (permalink)
0
can you tell me what changes should be done in chan FatFs library for
4Gb, 8GB sd card.clock  for high speed and Low_speed i have done and tested . it working fine for ADC MCP3008 IC. i dont know what is happening in Sd card.pink: pink
#4
katela
Super Member
  • Total Posts : 1186
  • Reward points : 0
  • Joined: 2013/06/11 05:25:18
  • Location: South Africa
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/21 07:51:24 (permalink) ☄ Helpfulby yo123 2019/03/01 03:31:49
0
I used a 4GB sd card (FAT32) with FatFs library and MCC with no problem. If your hardware configuration is correct, try using different sd cards from a different vendor.
You can download my project and compare from this link. I used PIC18F45k22.

Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
#5
yo123
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2017/04/19 09:52:08
  • Location: 0
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/21 09:59:04 (permalink)
0
katela
I used a 4GB sd card (FAT32) with FatFs library and MCC with no problem. If your hardware configuration is correct, try using different sd cards from a different vendor.
You can download my project and compare from this link. I used PIC18F45k22.


At the beginning at started from this and very helpful for me.
From the above reply I conclude that no one got result at  min try.
I should try more.
Tahnks
 
#6
katela
Super Member
  • Total Posts : 1186
  • Reward points : 0
  • Joined: 2013/06/11 05:25:18
  • Location: South Africa
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/21 10:10:15 (permalink)
0
If the hardware and software is fine and you have a good quality sd card, you should get it working at first try.
In my case, I din't build the hardware, I used a development board with an sd card breakout board.

Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
#7
yo123
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2017/04/19 09:52:08
  • Location: 0
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/22 05:36:53 (permalink)
0
hi ,
i am also working on explorer 16 dev board with sd card adapter( design for ardiuno and Pi) having 3.3 volatge shifter.
current update about my code
=> disk_initialize(0) return zero value that means card initialized properly.
=> disk_status(0) also return zero value.
but when jump to f_mount(). this function also executed but after  f_open() function the system get restarted continuously. what could be the problem???
 bw = select ();
     if(bw)
     {PORTA = 0b01010101;}   //card is ready/
        
     __delay_ms(1000);
     bw =disk_initialize(0);   //return zero if initialzed
     sprintf(buff,"%d",bw);
     lcd_clr();
     lcd_print(buff);
     if(bw)
     {
         PORTA = 1;
     }
     
      __delay_ms(1000);
      bw = disk_status(0);       
     sprintf(buff,"%d",bw);
     lcd_clr();
     lcd_print(buff);
     if(!bw)
     {
         PORTA = 2;
     }
      __delay_ms(1000);
       
     PORTA = 3;
     bw = xmit_datablock(dummy,0xFE);
     sprintf(buff,"%d",bw);
     lcd_clr();
     lcd_print(buff);
     __delay_ms(1000);
      PORTA = 4;

 
#8
qhb
Superb Member
  • Total Posts : 9623
  • Reward points : 0
  • Joined: 2016/06/05 14:55:32
  • Location: One step ahead...
  • Status: online
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/22 19:02:19 (permalink) ☄ Helpfulby yo123 2019/03/01 03:32:18
0
It's a good idea to get your terminology right to avoid confusion.
"SD" cards only go up to 2GB capacity, (although there was an extension that pushed this to 4GB, but not always compatible with other devices.)
"SDHC" cards can go up to 32GB.
Any card that is 4GB is almost certainly an SDHC card.
 
Ref: https://en.wikipedia.org/wiki/Secure_Digital#Comparison_to_other_flash_memory_formats
 
 
#9
yo123
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2017/04/19 09:52:08
  • Location: 0
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/01/24 07:42:38 (permalink)
0
Hii.
In initialization process I used 250kHZ Freq,can I use this Freq for reading and writing is SD card. Just for confirmation.
Thanks your valuable responsegrin: grin
#10
Pusb
Moderator
  • Total Posts : 103
  • Reward points : 0
  • Joined: 2004/02/09 09:47:27
  • Status: offline
Re: FatFs library for sd card interace with PIC24FJ128GA010 2019/04/12 11:42:10 (permalink)
0
MCC now has file system module support, FatFS, and SD card driver. Depends on Foundation Services SPI.
#11
Jump to:
© 2019 APG vNext Commercial Version 4.5