alok 0 Posted January 27, 2014 Share Posted January 27, 2014 can i store analog values of audio in different files , then seek one of the file based on some conditions and play it through pwm Quote Link to post Share on other sites
bluehash 1,581 Posted January 27, 2014 Author Share Posted January 27, 2014 Has it to be different files? You will have to pre-create the files on a windows PC with a fixed length. Quote Link to post Share on other sites
michaelo 0 Posted April 5, 2014 Share Posted April 5, 2014 Hello, i found a crittical bug, i am trying to read each time a diffrencet part from a file, by using "pf_lseek( ofs)" and then using " pf_read(Line, sizeof(Line), &s1)" . each time i am incriminating the ofs. eveything working great until im trying to read ofs>32768 . after a long recerch i found that this number means 32768/512 = 64 with means the "Allocation unit size" of the sdcard. when i tried to change the "Allocation unit size" to 64k. i got that the boundery is 65536/512 =128 , so now i could read much more.. but still with limit. i think that there is a problem with reading next block. but i dont know where to change it? Thank you all!! Quote Link to post Share on other sites
michaelo 0 Posted April 5, 2014 Share Posted April 5, 2014 After some tests and resources: when using pf_lseek( ofs) , ofs must be from 0 and up to the block size. My questions is what i should do ,to continue read from the next block? Thank you!! Quote Link to post Share on other sites
biza 0 Posted April 7, 2014 Share Posted April 7, 2014 hi, bluehash, I'am trying use a SDCARD only to regist data. Only to write, I noticed that there is already a SDPetit-fat library, my question is I' will have to use all the files? and what are the files that need only to write to the SD. I'm new to microcontrollers, can you recommend me a documentation of easy understanding the workings of SDCARD Quote Link to post Share on other sites
bluehash 1,581 Posted April 7, 2014 Author Share Posted April 7, 2014 The "working" of an SDcard is different from the FatFS layer that sits on top of it. I'm not thoroughly understanding your question. If you are using the Petite FatFs library, you will have to pre-create the file on your PC, then insert the cart into your embedded system and write/read from the file. Have you seen this - http://43oh.com/2013/12/interfacing-the-launchpad-to-an-sd-card-a-walkthrough/'>Interfacing An SD-Card To The Launchpad Quote Link to post Share on other sites
michaelo 0 Posted April 7, 2014 Share Posted April 7, 2014 Hey Bluehash, can you help me with my questions? when using pf_lseek( ofs) , ofs must be from 0 and up to the block size. My questions is what i should do ,to continue read from the next block? Quote Link to post Share on other sites
biza 0 Posted April 7, 2014 Share Posted April 7, 2014 I'm trying to register for multiple values ??in a sdcard, that's I'm trying do Quote Link to post Share on other sites
bluehash 1,581 Posted April 7, 2014 Author Share Posted April 7, 2014 Hey Bluehash, can you help me with my questions? when using pf_lseek( ofs) , ofs must be from 0 and up to the block size. My questions is what i should do ,to continue read from the next block? I was trying to get you an answer, but got distracted. I think you are hitting a data type boundary on ofs. What data type is ofs.. does it match pf_lseek declaration? I'm trying to register for multiple values ??in a sdcard, that's I'm trying do You are trying to write to the SD card? Quote Link to post Share on other sites
biza 0 Posted April 7, 2014 Share Posted April 7, 2014 yes, blueash Quote Link to post Share on other sites
michaelo 0 Posted April 7, 2014 Share Posted April 7, 2014 Thank you for your help! OFS is DWORD Im only trying to read from a file, each time from diffrent place ( at the same file). size of the file is 2 MB. so each time im setting the ofs , and calling pf_lseek( ofs) . but the ofs is limited from 0 to 32768 . everything working great when 0< ofs <32768 . but when im trying to read more , i got error Quote Link to post Share on other sites
bluehash 1,581 Posted April 7, 2014 Author Share Posted April 7, 2014 If you are trying to write to the SD-Card in a log fashion, you need to open the file, seek and write to it. Energia has an example here. Or from the ElmChan site: http://elm-chan.org/fsw/ff/pf/write.html File write operation must be done in following sequence. pf_lseek(ofs); read/write pointer must be moved to sector bundary prior to initiate write operation or it will be rounded-down to the sector boundary. pf_write(buff, btw, &bw); Initiate write operation. Write first data to the file. pf_write(buff, btw, &bw); Write next data. Any other file function cannot be used while a write operation is in progress. pf_write(0, 0, &bw); Finalize the write operation. If read/write pointer is not on the sector boundary, left bytes in the sector will be filled with zero. Quote Link to post Share on other sites
michaelo 0 Posted April 7, 2014 Share Posted April 7, 2014 pf_lseek(ofs); read/write pointer must be moved to sector bundary prior to initiate write operation or it will be rounded-down to the sector boundary. and how you move to other sector? Quote Link to post Share on other sites
Rickta59 589 Posted April 7, 2014 Share Posted April 7, 2014 http://elm-chan.org/fsw/ff/pf/lseek.html pf_lseek takes a 32 bit offset. This is how you move around. The comment about rounding down to a sector size is because that is how it accesses the data, a sector at a time. You can seek to locations that are multiples of the sector size. To move to an odd offset you must seek to the beginning of the sector and then read and throw out data until you reach the odd offset byte. pf_lseek(1024L); // move to the offset of 1024 bytes in the file. pf_lseek(512UL*1000UL); // move really far into the file. One "feature" people often overlook with the petite file system, you must pre-create and allocate the file to the maximum size you want to use. If you try to seek or write past the end of the pre allocated size, it is going to fail. -rick Quote Link to post Share on other sites
michaelo 0 Posted April 7, 2014 Share Posted April 7, 2014 As i understand , each file saved in the sd-card in a lot of blocks. each block is 32 bit size.( as in the picture) so if i will do this: long x=0; while(1) { pf_lseek(X++); pf_read(Line, sizeof(Line), &s1); } i will go over all the file? i tried to do so.. and after i reach the "111111..11" of the first block, i got error Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.