This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CCS/CC1350:如何将外部 SD 卡连接到 cc1350?

Guru**** 2539500 points
Other Parts Discussed in Thread: CC1350

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/757806/ccs-cc1350-how-to-connect-external-sd-card-to-cc1350

器件型号:CC1350

工具/软件:Code Composer Studio

我使用的是 CC1350。 我想使用外部存储器进行存储。 我为此使用了外部 SD 卡模块。 引脚配置如下  

VCC:- 3V3

GND:- GND

MOSI:- DIO9.

MISO:- DIO8  

SCK:- DIO10

CS:- DIO11

在代码中、我使用了 SD_open、其工作正常  

但 sd_initailize 不会返回任何值  

这是代码

#include 
#include 
#include 
#include 
#include 

/*驱动程序头文件*/
#include 
#include 

//示例/板头文件*/
#include "Board.h"

//文件复制过程中使用的缓冲区大小*/
#define BUFFSIZE 10

//开始扇区写入/读取*/
#define STARTINGSECTOR 0

#define BYTESPERKILOBYTE 1024//


*将此常量设置为1以写入 SD 卡。
*警告:在 WRITEENABLE 设置为1的情况下运行此示例将导致
* SD 卡上存在的任何文件系统损坏!
//
#define WRITEENABLE 0

unsigned char textarray[BUFFSIZE];

unsigned char CPY_buffSIZE];

//
*=== mainThread ====
*任务执行从 SD 卡进行原始写入和读取。
*注意:运行此应用程序将导致
* SD 卡上的任何文件系统损坏!
//
void * mainThread (void * arg0)
{
静态 int_fast16_t 结果;
uint_fast32_t cardCapacity;
uint_fast32_t totalSecors;
uint_fast32_t sectorSize;
uint_fast32_t 扇区;
int i;
sd_handle sdHandle;

GPIO_init();
sd_init();

/*配置 LED 引脚*/
GPIO_setConfig (Board_GPIO_LED0、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

/*打开用户 LED */
GPIO_WRITE (Board_GPIO_LED0、Board_GPIO_LED_ON);

printf ("启动 SD 示例\n");

// System_flush ();

/*初始化要写入 SD 卡的阵列*/
对于(I = 0;I < BUFFSIZE;I++)
{
textarray[i]= i & 0xFF;
}

/*安装并注册 SD 卡*/
SDHandle = SD_open (Board_SD0、NULL);
if (sdHandle == NULL)
{
printf ("启动 SD 卡时出错\n");
// System_flush ();
while (1)
;
}

//结果= sd_initialize (sdHandle);
if (sd_initialize (sdHandle)!= sd_status_Success)
{
printf ("初始化 SD 卡时出错\n");
// System_flush ();
while (1)
;
}

totalSecors = SD_getNumSecors (sdHandle);
sectorSize = SD_getSectorSize (sdHandle);
cardCapacity =(totalSectors / BYTESPERKILOBYTE)* sectorSize;

printf (" SD 卡上总共有%u 个扇区。\n"、totalSecitors);
// System_flush ();
printf ("读取/写入扇区大小为%u 字节\n"、sectorSize);
// System_flush ();
printf ("卡总容量为%u KB\n"、cardCapacity);
// System_flush ();

/*通过向上舍入计算数组占用的扇区数*/
扇区=(sizeof (textarray)+ sectorSize - 1)/ sectorSize;

#if (WRITEENABLE)
printf ("写入数组...\n");
// System_flush ();

结果= sd_write (sdHandle、textarray、STARTINGSECTOR、Sectors);
if (结果!= SD_STATUS_SUCCESS)
{
printf ("写入 SD 卡时出错\n");
// System_flush ();
while (1);
}
#endif

printf ("读取数组...\n");
// System_flush ();
结果= SD_Read (sdHandle、CPY_buff、STARTINGSECTOR、扇区);
if (结果!= SD_STATUS_SUCCESS)
{
printf ("从 SD 卡读取时出错\n");
// System_flush ();
while (1)
;
}

/*将从 SD 卡读取的数据与预期值进行比较*/
对于(I = 0;I < BUFFSIZE;I++)
{
if (cpy_buff [i]!=文本数组[i])
{
printf ("从 SD 卡读取的数据与预期值不同\n");
// System_flush ();
printf ("索引%d 的预期值:%d、得到了%d\n"、i、
textarray[i]、cpy_buff [i]);
// System_flush ();
printf ("运行 WRITEENABLE = 1的示例以将预期值写入 SD 卡\n");
// System_flush ();
中断;
}
}

如果(i == BUFFSIZE)
{
printf ("从 SD 卡读取的数据与预期值相符\n");
// System_flush ();
}

sd_close (sdHandle);

返回(NULL);
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    在论坛上发布代码时、请使用标记的代码格式工具 按钮。 这使得代码易于阅读、并可帮助您在论坛上更快地获得支持。 我修改了您之前的帖子、以反映该工具的使用情况。

    看起来您是从 sl吸引力 示例中开发的。 SD CS 线路的默认引脚位于 DIO_21上(请参阅 CC1350_LAUNCHXL.c 中的 gpioPinConfigs 和 sdhwspiAttrs)。 您是否尝试将 CS 连接到它?

    如果需要进一步调查、请发布逻辑分析仪屏幕截图。



    此致、
    Toby