Main Site Documentation

Write data with L command


#1

I am writing 72,000 characters to U0: with L command (SPI). I am monitoring MOSI and MISO lines to ALFAT

It looks like everything is transferred to ALFAT correctly. I send J command, I command, E command, K command, open file (TREK009.txt). Alfat responds correctly (no errors) for each command.

Send L command (“L 0>11940\r”)
Alfat responds - !00

I then send 72,000 characters (every 6 characters is 1 piece of data (in volts)

Then 0x02, 0x0E, 0x00

Alfat responds - $00011940 !00

Send close command

Alfat responds - !00

However, the file that is created on the USB drive (TREK009.txt) does not contain all the data. Only 9,948 out of 72,000. And not all of the 9,948 are correct.

If all the data is sent to ALFAT correctly, what needs to be done for ALFAT to send information to U0 correctly?


#2

I am writing 6000 characters to ALFAT at a time, and checking the SPI Busy line before sending the data.

The SPI clock is set to 400KHz. Slower or faster settings make the problem worse.

What should I look for to figure out why the all of the data is not sent to the flash drive?


#3

@ vb74 -

it doesn’t matter if W command, but for L command, it requires about 20ms to send whole block 8KB, it means at least 3.3MHz SPI clock master. So 400K is too low.

And L command requires block 8KB, you can not send few bytes then delay a bit then send few bytes again!

Of course the last block doesn’t need 8KB!

We tested at 3MHz it works fine but following that, better if it is 4Mhz or higher!


#4

@ vb74 -

[quote]
What should I look for to figure out why the all of the data is not sent to the flash drive? [/quote]

I think you did:

  • Block is not 8KB
  • Clock is slow

Both case ALFAT will pick old data in DMA register and save to flash. You can check in your saved data, some of them will be 0x00 or repeated.


#5

Thanks.

It looks like I will not be able to use the L command because my data is in blocks of 6bytes and 8K does not divide evenly by 6.

I have also been trying to use the W command, but also cannot get it to work. Is there a size constraint for the W command? Can I write 72,000 bytes by sending 4 frames with a payload of 18,000 each?

With the W command I see the SPI busy signal go high after writing only a small amount of data.


#6

@ vb74 -

“Block is 8KB, except for last block”, if you have 6KB, so the first block is also the last block, so 6KB will be fine.

Is there a size constraint for the W command

W command, there is 0xFFFFFFFF, about 4GB and this is also max of FAT32 for length of a file.
For SPI frame, there is 0xFFFF, means about 65KB, so 72000 bytes will be 2 frames

W command is ALFAT command, it is same for all SPI, I2C, UART
SPI frame is only for SPI, it is separated.

With the W command I see the SPI busy signal go high after writing only a small amount of data.

Don’t worry, just continue sending data when it goes low. This is high when the buffer is full or busy for something.

when it is high => stop sending, when it is low => continue sending,

In W command, you should send one byte one, delay time between 2 bytes is 4us at 24Mhz.This is important or data will be lost. If using L command, no delay needed.


#7

I said:

I mean you send at least 2 SPI frames, but you can send many frames. For me, i will send 72000/(3*1024), it is about 24 frames.

I selected 3KB for each frame because buffer size of ALFAT is 4KB

Note: Even frame is 3KB but Busy pin may go high, but that is normal, just need to pause and wait until it goes low.

Why don’t you start few bytes first instead of starting at 72000 bytes? When we understand how SPI frame work well then we start with larger buffer.