2638 views|1 replies

1455

Posts

1

Resources
The OP
 

【CH579M-R1】+U disk read/write [Copy link]

 This post was last edited by jinglixixi on 2020-10-18 10:45

An interesting test about USB read/write. The routine on the official website only provides an example of creating a new file on the USB flash drive, which is used to generate a text file.

  1. First, build the test circuit as shown in Figure 1;
  2. Download the compiled test program to the development board;
  3. Open the serial port debugging tool and run the routine, the execution effect is shown in Figure 2.

Figure 1 Test circuit

Figure 2 Creation and writing results

After inserting the U disk into the computer, you can indeed see the newly generated file NEWFILE1.TXT in the U disk, and its content is shown in Figure 3.

Figure 3 File content

Having the write function is certainly welcome, but how to read?

There is no follow-up in the routine, so I referred to other materials and supplemented the reading program by myself. The execution effect is shown in Figure 4.

Figure 4 Reading results

But the problem is that I clearly wrote "Note: This program reads and writes USB files in bytes, and simply demonstrates the function." How come the first 100 characters read are 100 "CCCCCCCCCC..." which have nothing to do with the written content? What is the problem?

Later I found out that the problem was with the following statement:

for ( i=0; i!=mCmdParam.ByteRead.mByteCount; i++ ) printf( "%C", mCmdParam.ByteRead.mByteBuffer );

Above, should be changed to:

for ( i=0; i!=mCmdParam.ByteRead.mByteCount; i++ ) printf( "%c", mCmdParam.ByteRead.mByteBuffer );

Figure 5 Correct reading result

The reading problem is finally solved!

Another problem I was concerned about was how to generate a BMP image file, so I generated a file with a BMP suffix by storing binary numbers. Then the trouble came.

What's going on?

That is, it really generates a file with that name, but the problem is that you can neither view its contents with WinHex nor delete it freely. If you continue this experiment, there is only one result, which is to reformat the USB drive, otherwise it will be unusable, but the formatting method may not work.

What should I do? I can only fight poison with poison. At first, I used the file deletion program on the development board to delete it, but unfortunately it didn't work. What else can I do?

So I first created a text file on the development board with the same file name, and then deleted the file. This time it worked, and the stubborn problem was removed from the USB drive!

The effect of deleting files is shown in Figure 6

Figure 6 Deleting files

In file operations, if the specified file directory does not exist, all files under the root directory will be listed, as shown in Figure 7.

Figure 7 Listing the root directory files

Is it possible to write binary byte data into a file? Of course it is possible. Look at the following program, isn't it clear that the carriage return and line feed characters are written into the file?

printf( "ByteWrite\n" );

i = sprintf( (PCHAR)buf,"Note: \xd\xaThis is a simple example of reading and writing USB flash drives in bytes.\xd\xa");

mCmdParam.ByteWrite.mByteCount = i;

mCmdParam.ByteWrite.mByteBuffer = buf;

s = CH579ByteWrite() ;

mStopIfError( s );

printf("Written successfully\n");

Later we will continue to explore the method of generating and reading BMP files in order to realize the function of digital photo frame on this development board.

This post is from Domestic Chip Exchange

Latest reply

Qinheng CH579M-R1 Development Board Review Summary post: https://bbs.eeworld.com.cn/thread-1140005-1-1.html   Details Published on 2020-10-19 10:37
 
 

1w

Posts

204

Resources
2
 

Qinheng CH579M-R1 Development Board Review

Summary post: https://bbs.eeworld.com.cn/thread-1140005-1-1.html

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
Personal signature

玩板看这里:

https://bbs.eeworld.com.cn/elecplay.html

EEWorld测评频道众多好板等你来玩,还可以来频道许愿树许愿说说你想要玩的板子,我们都在努力为大家实现!

 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list