Pic32MZ Sd Card-> File Single byte Read

General discussion on mikroC PRO for PIC32.
Post Reply
Author
Message
KriszAime
Posts: 24
Joined: 31 Oct 2017 15:38

Pic32MZ Sd Card-> File Single byte Read

#1 Post by KriszAime » 19 Oct 2018 16:17

Hi

I'm playing .wav -RIFF files throught SPI bus.
The standard FAT16 library gives Some File Read routines, but most of them are buffered.

I tried Mmc_Fat_Read(); and Mmc_Fat_ReadN();

Normally, the buffer is useful, but I need a continuous stream of data.

Buffered reading, though it's fast, until it's empty. Then, It will work for a long time by recharging the buffer again. (2-4ms)
While recharging, i cannout send audio data, because the controller busy with reading sectors.
That causes lagging, breaking, bad, almost terrible sound quality.

How can I get bytes 1 by 1 directly, without buffering?

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: Pic32MZ Sd Card-> File Single byte Read

#2 Post by filip.grujcic » 22 Oct 2018 10:33

Hi,

What you're describing doesn't seem to be the problem here.

Could you attach your code where you do this?

Kind regards,
Filip Grujcic

KriszAime
Posts: 24
Joined: 31 Oct 2017 15:38

Re: Pic32MZ Sd Card-> File Single byte Read

#3 Post by KriszAime » 22 Oct 2018 16:31

Maybe I was too complicated. Actually, this is a simple problem.

When SPI used to talk to the SD card, it reads sectors. 1 sector is 512 bytes long.

The Library reads 1 sector and stores it in a 512 byte long block of array. (read functions do this)

To Play Wav files, it needs to Send data about 22,050 or 44,100 times/second. (depends on sample rate)

When that 512 bytes long buffer ends, the PIC needs to read the next 512 bytes.(next sector) <- this is my problem.

Because reading 1 sector takes about 5-1 millisecond. That is way more, than a 22,050 Hz (~45us) signal needs.

To read 1 byte is fast. But reading 512 bytes of "chunks" of data is creating delays!

So the original question is: Is there a function that allow me to Read Single bytes from the card? (Without Puffer)
Or if not, how can i read multiple sectors byte-by-byte not to by sector-by sector?

User avatar
filip.grujcic
Posts: 822
Joined: 14 May 2018 08:34

Re: Pic32MZ Sd Card-> File Single byte Read

#4 Post by filip.grujcic » 23 Oct 2018 10:41

Hi,

Unfortunately, in the current library there are no functions for reading the data from sd card byte by byte. So in that case, you will have to write your own function for this.

Kind regards,
Filip Grujcic

KriszAime
Posts: 24
Joined: 31 Oct 2017 15:38

Re: Pic32MZ Sd Card-> File Single byte Read

#5 Post by KriszAime » 23 Oct 2018 15:09

Just a quick update:
Recently I've solved the problem.

By using the library for determine wich sector is the file starts, and write my own code for sending commands to the card and reading it, as it should be.

Now it can play up to CD quality sound (44KHz) without any problem.

Post Reply

Return to “mikroC PRO for PIC32 General”