FAT Keeps Returning 255

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Wed Sep 19, 2012 9:54 am

Hi Jordy,

The file is created but empty, sorry to say :cry:


Have you created a simple example to see if you can replicate the issue? If you can do this then I can have a go on my hardware here for you. Otherwise maybe the compiler messages output file from your big program would help to see if anything is potentially going wrong.

Maybe also look at the high speed demo fro the Flowcode examples download and see if this is working for you. As yet no other reports of any issues with the code so I am suprised. Were you using the ARM hardware? If so I will investigate on this.

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Postby rocket200 » Wed Sep 19, 2012 9:55 pm

Benj wrote:Hello,

is there a way to read just ONE byte from the 512 byte buffer on the SD card? Transferring the entire buffer from the SD card to the local buffer takes way too much time. I would just read off each sector buffer of my 12 files, then store them in the AVR's ram, but 6.1 kbytes is too large for the RAM. By sending just one byte per file over the SPI bus, I save a ton of time.


I'm afraid the memory of the card is accessed in 512 byte sectors. I have put some thought in trying to get rid of the 512 byte buffer but I just don't think it's possible. Looking at other software FAT drivers I am yet to come across one that didn't have at least a 512 byte buffer. You could read a single byte but if you did not clock through the rest of the sector then the card would be in a non ready state when you tried to do the next operation meaning your not really saving any time anyway. Also it's not as simple as saying I want that byte as you can only address the memory via the sector address.

I still think using a PC to combine the files in some way prior to running will give you the best results.


Alright. Is there a way to jump to specific sectors of a file other than looping the Move_To_Next_File_Sector macro?

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Wed Sep 19, 2012 10:23 pm

Hello,

Alright. Is there a way to jump to specific sectors of a file other than looping the Move_To_Next_File_Sector macro?


It might be possible for me to make a skip to function that allows you to skip directly to an offset sector in the file and maybe also directly to the end of the file if appending data using the high speed technique rather then the append string function. I will have a play around in the next few days and see how easy it is.

Can you explain any further on what you are doing and what you need the system to be able to do. eg. how you intend to sync the playback up on the chip, do all the data formats have to match etc. This may help me to give you a better solution.

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Postby rocket200 » Thu Sep 20, 2012 1:47 am

Benj wrote:Hello,

Alright. Is there a way to jump to specific sectors of a file other than looping the Move_To_Next_File_Sector macro?


It might be possible for me to make a skip to function that allows you to skip directly to an offset sector in the file and maybe also directly to the end of the file if appending data using the high speed technique rather then the append string function. I will have a play around in the next few days and see how easy it is.

Can you explain any further on what you are doing and what you need the system to be able to do. eg. how you intend to sync the playback up on the chip, do all the data formats have to match etc. This may help me to give you a better solution.


Hi,

So basically what I am doing is creating a piece for an interactive museum for children. I have attached a layout of how it is going to work. Basically there is a carpeted floor that has 12 on/off triggers in a 3x4 grid under it that are about 1x1 feet in size. On top of the carpet is a 1x1 colored tile, indicating that something will happen when you step on that particular spot. When you step on each trigger, it is supposed to play a sound. A few of the sounds are a xylophone, pot clang, and a drum hit. The point is to get kids to come up with some way of creating a musical orchestra by having their buddies step on certain tiles at certain times. I have been trying to create basically a sampler that plays these samples when kids depress the triggers. I need to create the sampler myself because the budget is very tight, and I like the challenge of making my own. :) Each sample is a .WAV in a PCM format, 8bits at 44.1khz. As you know, the microcontroller I am using will be an AVR. The audio will be ouputted by a 12bit serial DAC. The particular one I had in mind is the DAC7611. http://www.ti.com/lit/ds/symlink/dac7611.pdf Here is where the trouble starts, each sample needs to be capable of playing polyphonically. The reason it needs to be capable of polyphony is because if one kid may step on one trigger, then another kid might step on another trigger at the same time.

Here is my code structure that I have been trying: Read triggers (finds that trigger 1,2, and 5 are pressed) => Get first audio byte of sample1, add to 16bit sum variable => Get first audio byte of sample2, add to 16bit sum variable => Get first audio byte of sample5, add to 16bit sum variable => Divide 16bit sum variable by 3 (3 samples being played) => Convert 16bit sum variable to 8bit variable => Fill up 112 byte buffer by looping back to start => When buffer is full, send buffer to buffer chip (another, smaller AVR) => Loop back to start => END

The second buffer AVR receives the buffer and sends it out to the DAC at a sample rate of 44.1khz. On the AVR, there is a interrupt that triggers on a Port change. Inside this interrupt it sends the audio bytes to the DAC. The interrupt port is triggered by the PWM generator connected to the change Port which has a period frequency of 44.1khz. This allows precise timing of the output to the DAC.

By having another AVR receive the buffer and output the buffer, the first AVR is given a little time to do its processes. This will prevent any glitches in the audio.

Hopefully that made a little sense. Thank you so, so much for helping me!

Henry


Layout:

Image

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Postby rocket200 » Sat Sep 29, 2012 1:51 am

It's nearly impossible to do it this way, isn't it? Maybe the only way is to use an XMega AVR with 16kb of RAM.

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 716 times
Contact:

Re: FAT Keeps Returning 255

Postby JohnCrow » Sun Sep 30, 2012 4:14 pm

Just got hold of a couple of Sandisk Ultra 16GB Class 10
Supposed to be capable of 30Mb/s
These work fine - formatted as FAT32
1 in 10 people understand binary, the other one doesn't !

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 27 times
Been thanked: 190 times
Contact:

Re: FAT Keeps Returning 255

Postby Jordy101091 » Sun Sep 30, 2012 8:32 pm

Benj wrote:Hi Jordy,

The file is created but empty, sorry to say :cry:


Have you created a simple example to see if you can replicate the issue? If you can do this then I can have a go on my hardware here for you. Otherwise maybe the compiler messages output file from your big program would help to see if anything is potentially going wrong.

Maybe also look at the high speed demo fro the Flowcode examples download and see if this is working for you. As yet no other reports of any issues with the code so I am suprised. Were you using the ARM hardware? If so I will investigate on this.


Hi ben sorry for the late reply lately im busy with school :roll:

As you know initilaizing of he sd card and creating a file works correctly.
When im trying opening the file that has been created, the card doesnt work anymore when Im inserting this card in my PC it says it needs to be formated.

Image

Im using the latest component files located in this topic.

also I have included the compilere message file.
Attachments
compiler message.txt
compilere message file
(23.59 KiB) Downloaded 115 times
the will to learn, should not be stopped by any price

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 27 times
Been thanked: 190 times
Contact:

Re: FAT Keeps Returning 255

Postby Jordy101091 » Sun Sep 30, 2012 8:38 pm

Benj wrote:Hi Jordy,

The file is created but empty, sorry to say :cry:


Have you created a simple example to see if you can replicate the issue? If you can do this then I can have a go on my hardware here for you. Otherwise maybe the compiler messages output file from your big program would help to see if anything is potentially going wrong.

Maybe also look at the high speed demo fro the Flowcode examples download and see if this is working for you. As yet no other reports of any issues with the code so I am suprised. Were you using the ARM hardware? If so I will investigate on this.


Hi ben,

Im having isues with the FAT component, but you already know that :wink:
By-The-Way sorry for the late respons im verry busy with school :roll:

But here a my result so far:

Init card = OK
Creating file = OK
Opening File = Not OK
Appending String to File = Not OK

When Im opening the file and appending a string this this file, when I insert this card into my PC I getting the message that it needs to format this card.
When Im not using the opening file macro I can see the file that has been created but there is not text in this file.
So my gues would be that there is a problem with the Opening File Macro.

Image

Also I have uploaded the compilere message

PS. in the attched image you cant find the create file macro because I have created this file on the PC incase this resolves the problem but it doesnt.
Attachments
compiler message.txt
(23.59 KiB) Downloaded 93 times
the will to learn, should not be stopped by any price

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Mon Oct 01, 2012 11:52 am

Hi Jordy,

So I can best match your setup please can you answer the following.

Are you using HW or SW SPI in the FAT component Properties?
What target clock speed are you using?
Which pins is the FAT component connected to?

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 27 times
Been thanked: 190 times
Contact:

Re: FAT Keeps Returning 255

Postby Jordy101091 » Mon Oct 01, 2012 2:35 pm

Hi Ben,

Im using SW SPI in the fat component
My Clock speed is 25Mhz

The pins are configured as:

CS - PORTF.2
CLK - PORTF.1
DATA IN - PORTF.3
DATA OUT - PORTF.0

Im using this microcontroller: PIC18F8722

Image
the will to learn, should not be stopped by any price

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Postby rocket200 » Tue Oct 02, 2012 8:27 pm

Ben,

Do you have any thoughts on my project?

Henry

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Wed Oct 03, 2012 10:24 am

Hello Jordy,

I have tested this using the software mode on the ECIO running at 48MHz and it is working well.

FAT_Test.fcf
(13.5 KiB) Downloaded 117 times


One thing you could try if the program is still failing for you is to switch the port references with lat references. I have customised the example below with the LAT definitions replacing the Port definitions and confirmed this also works ok on hardware.

FAT_Test_Customised.fcf
(23.28 KiB) Downloaded 115 times


I have highlighted the definitions I have changed via the custom code feature.

Code: Select all

//Definitions for CS control line
#define %a_MX_SPI_FAT_CS_PIN      %i
#define %a_MX_SPI_FAT_CS_PORT      lat%j         //***************** Edited ***************
#define %a_MX_SPI_FAT_CS_TRIS      tris%j


//Definitions for SPI slot allocation
#ifndef   MX_SPI_REF1
   #define MX_SPI_REF1
   #define %a_MX_SPI_UREF         1
   #define MX_SPI_CHANNEL_1      %b
   #define MX_SPI_MOSI_PIN_1      %c
   #define MX_SPI_MOSI_PORT_1      lat%d         //***************** Edited ***************
   #define MX_SPI_MOSI_TRIS_1      tris%d
   #define MX_SPI_MISO_PIN_1      %e
   #define MX_SPI_MISO_PORT_1      port%f
   #define MX_SPI_MISO_TRIS_1      tris%f
   #define MX_SPI_SCK_PIN_1      %g
   #define MX_SPI_SCK_PORT_1      lat%h         //***************** Edited ***************
   #define MX_SPI_SCK_TRIS_1      tris%h
   #define MX_SPI_CS_PIN_1         0
   #define MX_SPI_CS_PORT_1      0
   #define MX_SPI_BMODE_1         1
   #define MX_SPI_PR_SCALE_1      16
   #define MX_SPI_PO_SCALE_1      1
   #define MX_SPI_INT_1         0

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Wed Oct 03, 2012 10:25 am

Hi Henry,

What about having say 12 AVRs running with 12 different SD cards all hooked up to the same output using diodes to control the current flow. Probably overkill for what you need but the chips and hardware etc shouldn't be that expensive if your making a custom board anyway and this will simplify the software requirement no end.

I suppose what is needed first is to check that a single AVR can stream a file from the card at 44kHz.

rocket200
Posts: 68
Joined: Mon Oct 24, 2011 7:50 pm
Has thanked: 11 times
Been thanked: 3 times
Contact:

Re: FAT Keeps Returning 255

Postby rocket200 » Wed Oct 03, 2012 2:59 pm

Benj wrote:Hi Henry,

What about having say 12 AVRs running with 12 different SD cards all hooked up to the same output using diodes to control the current flow. Probably overkill for what you need but the chips and hardware etc shouldn't be that expensive if your making a custom board anyway and this will simplify the software requirement no end.

I suppose what is needed first is to check that a single AVR can stream a file from the card at 44kHz.


Great idea! You're totally right, the price would not be much of a problem, considering how cheap AVRs are these days. I have tested playing back the audio, and so far I have been able to get 48khz 8 bit no problem, and it sounds fantastic. I think this is what I might do!

Thank you sooo much!

Henry
These users thanked the author rocket200 for the post:
Benj (Thu Oct 04, 2012 10:50 am)
Rating: 5.26%
 

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 27 times
Been thanked: 190 times
Contact:

Re: FAT Keeps Returning 255

Postby Jordy101091 » Thu Oct 04, 2012 10:02 am

Hi Ben,

I have tried your example program along with the modifications to the C code,
The ad card doesn't need to be formatted anymore it creates the file correctly but it doesn't append a string to this file.

I have checked and rechecked my hardware and software connections in case this is the problem but its al OK.

Sorry to say this, wath can we do to fix this issue.

Regards jordy
the will to learn, should not be stopped by any price

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Thu Oct 04, 2012 10:59 am

Hi Jordy,

Are you able to replicate this problem on a number of cards or are you only testing using a single card?

Are you able to change the port pins you have connected to the card to see if there is anything specific with the current I/O pins your using?

Looking at the datasheet PortF is shared with some ADC inputs and maybe a comparator too.

This automatic line of code in the startup should be taking care of the analogue inputs.

adcon1 = 0x0F;

And from the datasheet it looks like the comparator module is disconnected by default.

I will have a think on it and see if anything else pops into mind.

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 27 times
Been thanked: 190 times
Contact:

Re: FAT Keeps Returning 255

Postby Jordy101091 » Thu Oct 04, 2012 11:54 am

Hi Ben thanks for your (quick) reply,

unfortunately I cannot switch to other IO pins because everything is solderd up and it's SMD so this is not a option.
However I can try to disable the ADC's to see if this causes the problem.
I will let you know ASAP, I'm currently @ work :roll:

Anyway thanks for the helping hand,

Regards jordy

PS. I have tested three different card,

1. 128MB from kingston
2. 1G " "
3. 1G micro in adapter from Kingston

All cards have the problem.
the will to learn, should not be stopped by any price

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 27 times
Been thanked: 190 times
Contact:

Re: FAT Keeps Returning 255

Postby Jordy101091 » Thu Oct 04, 2012 6:43 pm

Ben,

I have tried your solution to disable the ADC channels on port F but doesn't change much.
I can create file but the append to string doesn't work or opening file don't know.

Hope your crystal ball can give some answers :wink:

Regards Jordy
the will to learn, should not be stopped by any price

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Fri Oct 05, 2012 9:35 am

Hi Jordy,

The last thing I can think of is to basically try running the SPI at a lower speed. However as you are using the software mode I'm not sure how much of an impact this will have on the overall speed.

Select the FAT component on the panel and click custom code.

Then select the Init Card function and click edit.

Then find this line near the bottom of the function.

Code: Select all

   %a_SPI_Set_Prescaler(0);            //1:4


And try upping the value from 0.

eg.

Code: Select all

   %a_SPI_Set_Prescaler(2);            //1:4


The software SPI can accept any value up to 255 and basically sets the number of nops (no operations) between each SPI clock cycle.

The init routine is currently set to 1 and then backs off to 2 if the init function fails so you could maybe also customise the Init Fat Function slow down the back off speed.

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 27 times
Been thanked: 190 times
Contact:

Re: FAT Keeps Returning 255

Postby Jordy101091 » Fri Oct 05, 2012 6:47 pm

Hi ben,

Very much thanks for your help, but I dont get it to work. I need to make something else to get the same result maybe I will use EEPROM as a storage location.
Ore something like a RF Datalogger, but dont know if you can use 3 RF modules to communicate with each other, that would be really cool.

Hope you can give me an answer to this RF module thing, Also what would you recommend are advice to check if my RF module is really transmitting data.
PS. I have moved up to the transiever type, not because of you ben, dont get me wrong here :wink:

anyway thank for your advice and help.

Regards Jordy
the will to learn, should not be stopped by any price

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Mon Oct 08, 2012 9:59 am

Hi Jordy,

Hmm I wonder what is causing the FAT issue for you.

PS. I have moved up to the transceiver type, not because of you ben, dont get me wrong here :wink:


Sorry Jordy, not enough hours in the day. Hopefully I will get around to this soon.

For the RF transceivers in v5 I have implemented CRC checks to ensure that the data coming in is correct. This allows you to be sure that something is transmitting rather then just receiving random noise. The transceivers also work together in that multiple nodes can be listening to the same message. As long as no two nodes are transmitting at the same time you should be ok.

The additional variable sync byte can be used to create coexisting wireless networks should this be required.

User avatar
STibor
Posts: 262
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 115 times
Been thanked: 112 times
Contact:

Re: FAT Keeps Returning 255

Postby STibor » Tue Jan 08, 2013 11:12 pm

Benj wrote:Hi Henry,

What about having say 12 AVRs running with 12 different SD cards all hooked up to the same output using diodes to control the current flow. Probably overkill for what you need but the chips and hardware etc shouldn't be that expensive if your making a custom board anyway and this will simplify the software requirement no end.

I suppose what is needed first is to check that a single AVR can stream a file from the card at 44kHz.


Hi Ben!
Please upload a sample project.
I tried: @ Pic18F252 (40MHz), 18F4550 (48MHz) and now 18F26K20 (64MHz clock), but it's still a 8khz wav sound is noisy and impulsive popping sounds in it. SPI software with a voice broken with hardware SPI with a clicking sound can be heard in the music. R2R digital and PWM converter is the same sound.
I get a compile time error stack owerflow:
Serious Warning: Possible sw stack corruption, function 'FCD_FAT160_Read_Byte_From_Buffer' Call by more than one asynchronous thread (main / Task, interrupt, interrupt low)
This timer interruption in reading refers Fat.
Maybe that's the problem?
Thank you!
Attachments
wav 26k20_tmr2_V2.fcf
(60.59 KiB) Downloaded 70 times

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Fri Jan 11, 2013 3:53 pm

Hello,

There are two buffers which are populated and these both have to work together to allow the audio to stream without any ticks or other corruption.

Is the WAV file the only file on the card? Might be worth formatting the card and then placing the wav file on as this will ensure the file is at the start of memory and mean that the PIC has to do less big calculations to read back the data.

Might also be worth changing the buffer model so you buffer more then a single 512 byte sector before starting to stream. Depends how much free RAM you have on your device.

User avatar
STibor
Posts: 262
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 115 times
Been thanked: 112 times
Contact:

Re: FAT Keeps Returning 255

Postby STibor » Fri Jan 11, 2013 4:33 pm

Hello!

Thank you for your response.
A single WAV file on the card.
I tried FAT16 and FAT32 file system format.
512byte block size and a fat32 formatted.
Hardware SPI only works Transcend Memory (2 and 8Gbyte)
The Kingston 2Gbyte software only works with SPI.
The Pic18F26K20 3.3Volt working voltage, serial data lines 1kOhm resistor connected to the SD card and pulled 10kOhm resistor from Vdd. I tried the file operations works perfectly for reading and writing, but the sound quality is poor play.
The music playback quality is good, just popping in (2-3Hz) should be eliminated.
I thought I could be an oweflow the stack, can cause synchronization problems.
I tried the compiler with the-swcs6, 2 parameters, but nothing has changed.
The 18F26K20 microcontroller stack is 31 levels.

Have a nice day!

User avatar
Benj
Matrix Staff
Posts: 14567
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4598 times
Been thanked: 4239 times
Contact:

Re: FAT Keeps Returning 255

Postby Benj » Fri Jan 11, 2013 5:01 pm

Hello,

I've not tested this so it might not work but should be a good starting point. The device your using has tonnes of memory so I have created two 512 bytes buffers. When one buffer is streaming the other is being filled with data and visa versa.

WAV_Player_PIC_8khz_8bit_Mono.fcf
(27.68 KiB) Downloaded 112 times


Let me know how you get on. You could go up to 3 or 4 buffers on your device if your still experiencing issues with two full buffers.
These users thanked the author Benj for the post:
STibor (Mon Jan 14, 2013 7:35 pm)
Rating: 5.26%