TI中文支持网
TI专业的中文技术问题咨询交流网站

CC1310: cc1310 spi

Part Number:CC1310

1.cc1310,在使用的两个spi时,一个外接传感器,一个外接sd卡,无法同时使用,使用一个时,另外一个spi打开失败

Cherry Zhou:

您好,我们已收到您的问题并升级到英文论坛寻求帮助,如有答复将尽快回复您。谢谢!

,

desheng li:

static int sdspiinit(void){    SD_Handle     sdHandle;    uint8_t   result;    SD_init();    sdHandle = SD_open(Board_SD0, NULL);    if (sdHandle == NULL) {        while (1);    }    result = SD_initialize(sdHandle);    if (result != SD_STATUS_SUCCESS) {        while (1);    }    sd.handle = sdHandle;    GPIO_write(CC1310_LAUNCHXL_SPI0_CSN,0);    return 0;}

static int memsSpiInit(void){    SPI_Params       spiParams;    SPI_Handle       memsSpiHandle;    SPI_init();                                  //    SPI_Params_init(&spiParams);                 /    spiParams.mode =  SPI_MASTER;                 //spiParams.bitRate = 5000000;                    spiParams.bitRate = 4000000;     spiParams.dataSize = 8;                      spiParams.frameFormat = SPI_POL1_PHA1;           memsSpiHandle = SPI_open(Board_SPI1, &spiParams);    if( memsSpiHandle==NULL )    {        //SPI_open() failed, Error opening SPI        SPI_close(memsSpiHandle);        return -1;        //while (1);    }    return 0;}

前后运行这两个函数,后面的那个打开为NULL。

,

Cherry Zhou:

好的收到您提供的信息,已经跟进给工程师了,如有答复将尽快回复您。谢谢!

,

Cherry Zhou:

您好,请问下 Board_SD0 和 Board_SPI1 的定义是?

,

desheng li:

#define Board_SD0               CC1310_LAUNCHXL_SDSPI0

#define Board_SPI1              CC1310_LAUNCHXL_SPI1

#define CC1310_LAUNCHXL_SPI0_MISO             IOID_14          /* RF1.20 */  //闪存SD卡对应的引脚#define CC1310_LAUNCHXL_SPI0_MOSI             IOID_15         /* RF1.18 */#define CC1310_LAUNCHXL_SPI0_CLK              IOID_10         /* RF1.16 */#define CC1310_LAUNCHXL_SPI0_CSN              IOID_11#define CC1310_LAUNCHXL_SPI1_MISO             IOID_5          //传感器对应的引脚#define CC1310_LAUNCHXL_SPI1_MOSI             IOID_6#define CC1310_LAUNCHXL_SPI1_CLK              IOID_10#define CC1310_LAUNCHXL_SPI1_CSN              IOID_4

是这样定义的,

,

Cherry Zhou:

好的收到,反馈给工程师了哈。

,

YiKai Chen:

SPI是共用的,你只能init一個,然後使用不同的CS腳位去控制一个外接传感器和另一个外接sd卡

,

desheng li:

两个SPI,CLK是共用的,您说的是SD_init和spi_init,只能init一个?

,

YiKai Chen:

對,因為SD_init最後還是會調用SPI_init

,

desheng li:

    SD_init();    sdspiinit();                //sd init    memsSpiInit();                //spi init

static int sdspiinit(void){    SD_Handle     sdHandle;    uint8_t   result;    sdHandle = SD_open(Board_SD0, NULL);    if (sdHandle == NULL) {        while (1);    }    result = SD_initialize(sdHandle);    if (result != SD_STATUS_SUCCESS) {        while (1);    }    sd.handle = sdHandle;    return 0;}

static int memsSpiInit(void){    SPI_Params       spiParams;    SPI_Handle       memsSpiHandle;//    SPI_init();                                      SPI_Params_init(&spiParams);                     spiParams.mode =  SPI_MASTER;                              spiParams.bitRate = 3000000;    spiParams.dataSize = 8;                        spiParams.frameFormat = SPI_POL1_PHA1;          memsSpiHandle = SPI_open(Board_SPI1, &spiParams);    if( memsSpiHandle==NULL )    {        //SPI_open() failed, Error opening SPI        SPI_close(memsSpiHandle);        return -1;        //while (1);    }    return 0;}

,这样写,还是会失败

,

YiKai Chen:

你SPI_open也不能在沒有SPI_close前重複調用

,

desheng li:

您好,把SPI_close注释掉,SPI_open打开还是null, 你们是怎么使用两个spi的

,

desheng li:

 SPI_Handle     sdHandle;  SPI_Handle     sdHandle0;

    GPIO_init();    SPI_init();

    sdHandle = SPI_open(Board_SPI0, NULL);    sdHandle0 = SPI_open(Board_SPI1, NULL);    if (sdHandle == NULL) {        Display_printf(display, 0, 0, "Error starting the SD card\n");        while (1);    }    if (sdHandle0 == NULL) {        Display_printf(display, 0, 0, "Error starting thespi\n");        while (1);    }

这样写,    sdHandle0 = SPI_open(Board_SPI1, NULL);打开为NULL;还是打不开

,

YiKai Chen:

你的Board_SPI0/Board_SPI1定義是什麼?

,

desheng li:

CC1310_LAUNCHXL.h

#define CC1310_LAUNCHXL_SPI1_MISO             IOID_5          /* RF1.20 */     //sensor#define CC1310_LAUNCHXL_SPI1_MOSI             IOID_6          /* RF1.18 */#define CC1310_LAUNCHXL_SPI1_CLK              IOID_10         /* RF1.16 */#define CC1310_LAUNCHXL_SPI1_CSN              IOID_4#define CC1310_LAUNCHXL_SPI0_MISO             IOID_14           //sd#define CC1310_LAUNCHXL_SPI0_MOSI             IOID_15#define CC1310_LAUNCHXL_SPI0_CLK              IOID_10#define CC1310_LAUNCHXL_SPI0_CSN              IOID_11

Board.h

#define Board_SPI0              CC1310_LAUNCHXL_SPI0#define Board_SPI1              CC1310_LAUNCHXL_SPI1

分别是这样定义的

,

YiKai Chen:

你SPI_open的第二個參數要處理,如下:

SPI_HandlemasterSpi;SPI_ParamsspiParams;/* Open SPI as master (default) */SPI_Params_init(&spiParams);spiParams.frameFormat = SPI_POL0_PHA1;spiParams.bitRate = 4000000;masterSpi = SPI_open(Board_SPI1, &spiParams);

,

desheng li:

SPI_Handle     sdHandle;    SPI_Handle     sdHandle0;    GPIO_init();    SPI_init();    SPI_Params       spiParams;    SPI_Params       spiParams0;    SPI_Params_init(&spiParams);    spiParams.mode =  SPI_MASTER;                      spiParams.bitRate = 3000000;     spiParams.dataSize = 8;                       spiParams.frameFormat = SPI_POL1_PHA1;    SPI_Params_init(&spiParams0);    spiParams0.mode =  SPI_MASTER;                  spiParams0.bitRate = 3000000;     spiParams0.dataSize = 8;                      spiParams0.frameFormat = SPI_POL0_PHA1;    sdHandle = SPI_open(Board_SPI0, &spiParams);    sdHandle0 = SPI_open(Board_SPI1, &spiParams0);

这样写,第二个还是不可以

,

YiKai Chen:

我用下面的程序取代sdraw mainThread理的程序去測試SPI open,是沒問題的

SPI_HandlemasterSpi0;SPI_ParamsspiParams0;SPI_HandlemasterSpi;SPI_ParamsspiParams;SPI_init();/* Open SPI as master (default) */SPI_Params_init(&spiParams0);spiParams0.frameFormat = SPI_POL0_PHA1;spiParams0.bitRate = 4000000;masterSpi0 = SPI_open(Board_SPI0, &spiParams0);if (masterSpi0 == NULL) {Display_printf(display, 0, 0, "Error initializing master SPI 0\n");while (1);}else {Display_printf(display, 0, 0, "Master SPI 0 initialized\n");}SPI_Params_init(&spiParams);spiParams.frameFormat = SPI_POL0_PHA1;spiParams.bitRate = 4000000;masterSpi = SPI_open(Board_SPI1, &spiParams);if (masterSpi == NULL) {Display_printf(display, 0, 0, "Error initializing master SPI\n");while (1);}else {Display_printf(display, 0, 0, "Master SPI initialized\n");}

,

desheng li:

使用您的程序。第二个还是打不开?

CC1310_LAUNCHXL.c,这里面有没有哪些地方需要修改的

,

YiKai Chen:

重新安裝SDK然後用全新的程序試試看吧,我這邊測試是沒問題的

,

desheng li:

您好,当CLK没有共用时,可以打开,可能是CLK共用的问题?CLK不是可以共用么?

,

YiKai Chen:

你用兩組不同的spi,所有的spi腳位包和CLK都是不可以共用的

,

desheng li:

spi 多个设备,cs不共用,不就可以么,

,

YiKai Chen:

要cs不共用,其他腳位共用,你只能開一組SPI

,

desheng li:

       GPIO_write(CC1310_LAUNCHXL_SPI0_CSN,1);

我还有一个问题,片选信号,这样写,可以实现拉高么?

,

YiKai Chen:

可以

,

desheng li:

谢谢您,

       SPI_close(masterSpi0);

关闭一个,另外一个可以使用了,

,

YiKai Chen:

可以用就好,不客氣

,

desheng li:

谢谢您的帮助

,

desheng li:

您好,两个spi,和DMA的关系大么,dma如何设置

,

YiKai Chen:

spi預設會使用dma,你可以參考 https://dev.ti.com/tirex/explore/node?node=AOng5xFsavzvQ16.KytQHg__eCfARaV__LATEST 跟 https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/604406/ccs-cc1310-is-cc1310-s-spi-already-using-dma-transmission 這個討論串

,

desheng li:

您好,spi使用中,可以不用DMA?如何关掉DMA配置

,

YiKai Chen:

目前ti應該沒有提供关掉DMA配置的spi driver,你為什麼需要關掉呢?

,

desheng li:

#define CC1310_LAUNCHXL_SPI1_MISO             IOID_5          /* RF1.20 */     //sensor#define CC1310_LAUNCHXL_SPI1_MOSI             IOID_6          /* RF1.18 */#define CC1310_LAUNCHXL_SPI1_CLK              IOID_10         /* RF1.16 */#define CC1310_LAUNCHXL_SPI1_CSN              IOID_4#define CC1310_LAUNCHXL_SPI0_MISO             IOID_14           //sd#define CC1310_LAUNCHXL_SPI0_MOSI             IOID_15#define CC1310_LAUNCHXL_SPI0_CLK              IOID_10#define CC1310_LAUNCHXL_SPI0_CSN              IOID_11

使用两个spi,无法同时使用,关闭一个,另外一个才可以使用

,

YiKai Chen:

之前不是有給你可以成功SPI_open的範例程序?

,

desheng li:

之前,我是关掉一个,在打开另一个的,现在想同时使用,不关掉也可以使用,

,

YiKai Chen:

你是說你還是不能同時SPI_open兩个spi?

,

desheng li:

是的,用您的程序,一个可以打开,另一个就打不开了

,

desheng li:

,

YiKai Chen:

我剛剛又試了一次是沒問題的啊,你可以把你的mainThread完整程序貼上來給我看看嗎?

,

desheng li:

void *mainThread(void *arg0){    SPI_Handle      masterSpi0;    SPI_Params      spiParams0;    SPI_Handle      masterSpi;    SPI_Params      spiParams;       SPI_init();       /* Open SPI as master (default) */       SPI_Params_init(&spiParams0);       spiParams0.frameFormat = SPI_POL0_PHA1;       spiParams0.bitRate = 4000000;       masterSpi0 = SPI_open(Board_SPI0, &spiParams0);       if (masterSpi0 == NULL) {           Display_printf(display, 0, 0, "Error initializing master SPI 0\n");           while (1);       }       else {           Display_printf(display, 0, 0, "Master SPI 0 initialized\n");       }//       SPI_close(masterSpi0);////       GPIO_write(CC1310_LAUNCHXL_SPI0_CSN,0);//       GPIO_write(CC1310_LAUNCHXL_SPI1_CSN,1);       SPI_Params_init(&spiParams);       spiParams.frameFormat = SPI_POL0_PHA1;       spiParams.bitRate = 4000000;       masterSpi = SPI_open(Board_SPI1, &spiParams);       if (masterSpi == NULL) {           Display_printf(display, 0, 0, "Error initializing master SPI\n");           while (1);       }       else {           Display_printf(display, 0, 0, "Master SPI initialized\n");       }}

和您的一样的程序,只是在

#define CC1310_LAUNCHXL_SPI1_MISO             IOID_5          /* RF1.20 */     //sensor#define CC1310_LAUNCHXL_SPI1_MOSI             IOID_6          /* RF1.18 */#define CC1310_LAUNCHXL_SPI1_CLK              IOID_10         /* RF1.16 */#define CC1310_LAUNCHXL_SPI1_CSN              IOID_4#define CC1310_LAUNCHXL_SPI0_MISO             IOID_14           //sd#define CC1310_LAUNCHXL_SPI0_MOSI             IOID_15#define CC1310_LAUNCHXL_SPI0_CLK              IOID_10#define CC1310_LAUNCHXL_SPI0_CSN              IOID_11

我把两个spi的引脚配置改成这样,其他的没做修改了

,

desheng li:

unsigned char SPIreceiveByte(){    uint8_t  n=8;             //    uint8_t tdata;    uint8_t MISO;    GPIO_write(CC1310_LAUNCHXL_SPI1_CLK,1);    GPIO_write(CC1310_LAUNCHXL_SPI1_CSN,0);    while(n–)    {        CPUdelay(16);        GPIO_write(CC1310_LAUNCHXL_SPI1_CLK,0);           //时钟为低电平时,        CPUdelay(16);        tdata = tdata<<1;        MISO = GPIO_read(CC1310_LAUNCHXL_SPI1_MISO);        if(MISO == 1)            tdata = tdata|0x01;                           //接收位为1,数据最后一位为1        else            tdata = tdata&0xfe;        GPIO_write(CC1310_LAUNCHXL_SPI1_CLK,1);    }    GPIO_write(CC1310_LAUNCHXL_SPI1_CSN,1);    return(tdata);}

您好,io口可以这样模拟spi通讯么

,

YiKai Chen:

我用下面的腳位配置是可以的,你要不要試試

#define CC1310_LAUNCHXL_SPI0_MISOIOID_5/* RF1.20 */
#define CC1310_LAUNCHXL_SPI0_MOSIIOID_6/* RF1.18 */
#define CC1310_LAUNCHXL_SPI0_CLKIOID_10/* RF1.16 */
#define CC1310_LAUNCHXL_SPI0_CSNIOID_4
#define CC1310_LAUNCHXL_SPI1_MISOIOID_2
#define CC1310_LAUNCHXL_SPI1_MOSIIOID_3
#define CC1310_LAUNCHXL_SPI1_CLKIOID_19
#define CC1310_LAUNCHXL_SPI1_CSNIOID_18/* UART Board */
#define CC1310_LAUNCHXL_UART_RXPIN_UNASSIGNED/* RXD */
#define CC1310_LAUNCHXL_UART_TXPIN_UNASSIGNED/* TXD */
#define CC1310_LAUNCHXL_UART_CTSPIN_UNASSIGNED/* CTS */
#define CC1310_LAUNCHXL_UART_RTSPIN_UNASSIGNED/* RTS */

,

desheng li:

这样是可以打开的,硬件已经做好了,只能修改软件部分

,

YiKai Chen:

你的CC1310_LAUNCHXL_SPI1_CLK和CC1310_LAUNCHXL_SPI0_CLK要用不同腳位啊,不能共用IOID_10 

,

desheng li:

已经用了,板子做好了,用IO口模拟spi,不通过DMA

,

YiKai Chen:

如果要共用CLK,那基本上應該是連MOSI/MISO都要共用,只有不同的spi slave的CS接到不同腳位

,

desheng li:

现在没办法改硬件了,现在需要修改程序,用IO口模拟spi通讯,不通过DMA

,

YiKai Chen:

那你保重

赞(0)
未经允许不得转载:TI中文支持网 » CC1310: cc1310 spi
分享到: 更多 (0)