Netduino +以太网盾:如何写入SD卡?

发布于 2024-12-10 22:55:35 字数 1599 浏览 0 评论 0原文

我尝试了几个示例程序将数据写入安装在以太网盾上的SD卡,但是没有一个起作用。 SD 卡大小为 4 GB,格式为 FAT32

以太网扩展板如下:(

在亚马逊购买 - Arduino 以太网扩展板

在此处输入图像描述

这是创建 Netduino 应用程序时不起作用的示例代码(不是Netduino Plus应用程序)(第一行抛出异常):

public static void Main()
{
    StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_D10);

    string[] directories = System.IO.Directory.GetDirectories(@"\");
    Debug.Print("directory count: " + directories.Length.ToString());

    for (int i = 0; i < directories.Length; i++)
    {
        Debug.Print("directory: " + directories[i]);
    }

    string[] files = System.IO.Directory.GetFiles(@"\SD1");
    Debug.Print("file count: " + files.Length.ToString());

    for (int i = 0; i < files.Length; i++)
    {
        Debug.Print("filename: " + files[i]);
        FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512);
        StreamReader sr = new StreamReader(fs);
        Debug.Print("contents: " + sr.ReadToEnd());
    }
}

有示例工作程序吗?

解决方案:

感谢 Chris 和 James,我成功地写入 SD 卡并从中读取。将所有内容放在一起后,我写了一篇文章,以防其他人遇到同样的问题。

I have tried several example programs to write data to the SD card mounted on the Ethernet shield, but none worked. The SD card size is 4 GB and formatted as FAT32.

The Ethernet shield is the following:

(Bought on Amazon - Arduino Ethernet Shield)

Enter image description here

And this is example code that doesn't work when creating a Netduino application (not Netduino Plus application) (thefirst line throws an exception):

public static void Main()
{
    StorageDevice.MountSD("SD1", SPI_Devices.SPI1, Pins.GPIO_PIN_D10);

    string[] directories = System.IO.Directory.GetDirectories(@"\");
    Debug.Print("directory count: " + directories.Length.ToString());

    for (int i = 0; i < directories.Length; i++)
    {
        Debug.Print("directory: " + directories[i]);
    }

    string[] files = System.IO.Directory.GetFiles(@"\SD1");
    Debug.Print("file count: " + files.Length.ToString());

    for (int i = 0; i < files.Length; i++)
    {
        Debug.Print("filename: " + files[i]);
        FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512);
        StreamReader sr = new StreamReader(fs);
        Debug.Print("contents: " + sr.ReadToEnd());
    }
}

Is there a example working program?

Solution:

Thanks to Chris and James, I managed to write to the SD card and read from it. After putting everything together, I wrote an article, in case anyone else faces the same issues.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

后来的我们 2024-12-17 22:55:35

Arduino 以太网扩展板的最新版本使用“ICSP”接头(板右侧的 3x2、6 针接头)进行通信。进入 SD 卡的输入/输出数据将通过这些引脚。

为了兼容性,我们在 Netduino 上包含了这些相同的标头;要使用此屏蔽,您需要将适当的接头焊接到您的 Netduino 上。那么你就可以出发了!

顺便说一句,Netduino Plus 集成了 MicroSD 和快速以太网……这也可能是一个简单的解决方案。 http://www.netduino.com/netduinoplus/

Chris(Secret Labs LLC)

The latest revision of the Arduino Ethernet Shield uses the "ICSP" header (3x2, 6-pin header on right side of board) to communicate. The input/output data going to your SD card is going over those pins.

We've included these same headers on the Netduino for compatibility; to use this shield, you'll want to solder the appropriate header onto your Netduino. Then you should be good to go!

BTW, Netduino Plus has integrated MicroSD and fast Ethernet networking...which may be an easy solution as well. http://www.netduino.com/netduinoplus/

Chris (Secret Labs LLC)

梦里兽 2024-12-17 22:55:35

我在此论坛页面上找到了参考 http://forums.netduino.com

“您当前需要在 D10 和 D4 之间放置一根跳线才能获得
SD 卡才能工作——尽管这对于
Production v4.1.1 firwmare(它可以让你指定SD卡的
片选线)。”

这让我认为您需要为 SD 卡使用 D4 而不是 D10。我在同一页面上发现了一些其他参考资料,其中提到 D10 是以太网的 SS 引脚。固件可在他们的下载中找到页面目前只有 4.1.0,所以您可能需要跳线,我无法测试它,但论坛链接应该是一个很好的起点。

I found a reference on this forum page http://forums.netduino.com

"you'll currently need to put a jumper wire between D10 and D4 to get
the SD card to work--although that will not be necessary with the
production v4.1.1 firwmare (which will let you specify the SD card's
chip select line)."

Which makes me think that you need to use D4 instead of D10 for the SD Card. I found some other references on the same page that mentioned D10 is the SS pin for the Ethernet. The Firmware available on their download page is currently only 4.1.0 so you will probably need the jumper. I can't test this but the forum link should be a good starting point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文