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.

LAUNCHXL-CC1310: SPI Master transfer

Part Number: LAUNCHXL-CC1310
Other Parts Discussed in Thread: CC1310

您好:

        目前我在使用CC1310的SPI   Master模式,需求是SPI MASTER模式下可以一次发送256个字节, 按照API中的例程,可以正常发送Hello World,但是将需要发送的数组赋值为100个字节运行后,发现只能打出前28个字节。

     按照API说明:SPI的TX每次最多可以发送1024个字节:

        Transfer Size Limit

       The UDMA controller only supports data transfers of up to 1024 data frames. A transfer with more than 1024 frames will be transmitted/received in multiple 1024 sized portions until all data has been transmitted/received. A data frame can be 4 to 16 bits in length.

   目前有怀疑是不是超时时间没有设置好??  

Timeout

Timeout can occur in SPI_MODE_BLOCKING, there's no timeout in SPI_MODE_CALLBACK. When in SPI_MODE_CALLBACK, the transfer must be cancelled by calling SPI_transferCancel().
If a timeout happens in either SPI_SLAVE or SPI_MASTER mode, the receive buffer will contain the bytes received up until the timeout occurred. The SPI transaction status will be set to SPI_TRANSFER_FAILED. The SPI transaction count will be set to the number of bytes sent/received before timeout. The remaining bytes will be flushed from the TX FIFO so that the subsequent transfer can be executed correctly. Note that specifying a timeout prevents the driver from performing a polling transfer when in slave mode.

代码如下:

       

void *mainThread(void *arg0)
{
    GPIO_init();
    SPI_init();
    uint8_t x;
    SPI_Handle handle;
    SPI_Params params;
    SPI_Transaction transaction;
    uint8_t txBufdata[100];
    uint8_t rxBuf[11];
    SPI_Params_init(&params);
    params.bitRate     = 4000000;
    params.frameFormat = SPI_POL1_PHA1;
    params.mode        = SPI_MASTER;
    transaction.count = sizeof(txBufdata);
    transaction.txBuf = txBufdata;
    transaction.rxBuf = rxBuf;
    handle = SPI_open(Board_SPI_MASTER, &params);
    while(1)
    {
    for(x=0;x<100;x++)
       {
        txBufdata[x]=x;
       }
        SPI_transfer(handle, &transaction);
    }
}

       麻烦您看下或者提供下可用例程,谢谢!

  • 已为您联系TI资深工程师,一旦得到回复会立刻回复给您

  • 您是说想发送 256 字节,但 tx 缓冲区是 100 字节?

    我测试了以下内容,发送 256 字节没有任何问题:

    #define THREADSTACKSIZE (2048)
    #define SPI_MSG_LENGTH  (256)
    
    unsigned char masterTxBuffer[SPI_MSG_LENGTH];
    
    void *masterThread(void *arg0)
    {
        SPI_Handle      masterSpi;
        SPI_Params      spiParams;
        SPI_Transaction transaction;
        uint16_t        i;
    
        SPI_Params_init(&spiParams);
        spiParams.frameFormat = SPI_POL0_PHA1;
        spiParams.bitRate = 4000000;
        masterSpi = SPI_open(Board_SPI_MASTER, &spiParams);
    
        for(i = 0; i <= 255; i++)
        {
            masterTxBuffer[i] = i;
        }
    
        transaction.count = SPI_MSG_LENGTH;
        transaction.txBuf = (void *) masterTxBuffer;
        transaction.rxBuf = NULL;
    
        SPI_transfer(masterSpi, &transaction);
    
        while(1);
    }