I am using K60 with cw10.6. I have created a project with multiple files .i.e for each functions there is a separate file. I wanted to implement FATFs in main.c and Events.c but it didn't work (I tried this many times earlier this year) but it didn't worked so I made a separate file for this.
I tried using the functions present in this file from main as well as events.c but my program hanged. on init function. kindly look into this where I am doing wrong.
If I tried to use extern FATFs fs; or extern FIL fp1; in events.c i got errors so i made these files to overcome this issues. I am using FAT SD card library of Erich Styger. using SPI.
Original Attachment has been moved to: SD_Card.h.zip
Original Attachment has been moved to: SD_Card.c.zip
If you are using the TWR-K60, I recommend that you verify proper operation with one of the demo examples:
it looks like you are using it bare metal (without RTOS), so have a look here too:
Apart of that, I do not see the proper includes in your example code (e.g. include to WAIT1.h and FAT1.h is missing), and FAT1_Init() is not used.
The other thing to keep in mind: mount the file system only once (just in case this might be your problem).
Additionally, if you are using the FAT module,you need to feed the timeout timer so the SPI operation can timeout. See the implementation of this in the Events.c of both above examples.
I hope this helps,
Thanks for the quick reply. I looked at the links and checked the code and updated my code according to your suggestions but still it didn't worked. If I write all the code in main it works fine but my application requires it to work on interrupt based. Attached is the modified code generated in CW10.6. I am using custom made board.
It is a very, very bad idea to read/write files in an interrupt service routine. This is not how you should do things, and it cannot work that way.
If you are in an interrupt context, then interrupts are disabled (or at least most of them). But you need interrupts (e.g. timer for timeout, interrupts for SPI) active while writing/reading files.
If you need to trigger file I/O from an interrupt, then simply set a flag from that interrupt.
And do the writing/reading from your main application.
I hope this helps to understand the issue you are facing,
Thanks for the feedback. what if in the above program I generate a flag in an ISR as u suggested and in main functions call the SD card functions ? will it work in that case ?