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.

CC3220S: SPI miss 2 bytes between fh8610 and CC3220

Part Number: CC3220S

Hi,

SPI Parameters: dataSize 16bit, clock 6MHz, polarity 0, phase 0

Issue Detail: When the FH8610(slave) and CC3220 (master) communicate by SPI, the original buf is "123456789123456789", but the actual sending is "1256914589". In other words, 2 bytes are sent successfully, 2 bytes are lost,2 bytes are sent successfully, 2 bytes are lost ......  But receiving data from CC3220 is normal.

Do you have an idea what causes the SPI issue?

thanks

Kevin

/*********************FH8610 code**********************/
void config_spi( int id )
{
    Spi_Enable( id, 0 );
    Spi_SetFrameFormat( id, SPI_MOTOROLA_MODE );
    Spi_SetPolarity( id, SPI_POLARITY_LOW );
    Spi_SetPhase( id, SPI_TXR_PHASE );
    Spi_SetDataSize( id, ((SPI_UNIT_TR_BITS == 8) ? SPI_DATA_SIZE_8BIT : 0xf));
    Spi_SetTransferMode( id, SPI_TX_RX_MODE );
    Spi_DisableIrq( id, SPI_IRQ_ALL );
    Spi_SetDmaTxDataLevel( id, 12 );        //12
    Spi_SetDmaRxDataLevel( id, 3 );         //3
    Spi_SetDmaControlDisable( id, SPI_DMA_RX_POS | SPI_DMA_TX_POS );
     
}
static void config_dma_rx( int ch )
{
    Dma_ClearIsrBit(ch,(DMA_INTT_TXR | DMA_INTT_BLOCK | DMA_INTT_SOURCE | DMA_INTT_DEST | DMA_INTT_ERR)); // new add
     
    Dma_SetTxrType( ch, DMA_TTFC_P2M_DMAC );
    Dma_SetSrcWidth( ch, ((SPI_UNIT_TR_BITS == 8) ? DMA_TXR_8BITS : DMA_TXR_16BITS));
    Dma_SetSrcSize( ch, DMA_BURST_4 );
    Dma_SetDstWidth( ch, DMA_TXR_32BITS );  //DMA_TXR_32BITS
    Dma_SetDstSize( ch, DMA_BURST_4 );
    Dma_SetSrcIncDirection( ch, DMA_DIR_UNCHG );
    Dma_SetDstIncDirection( ch, DMA_DIR_INC );
    Dma_SetSrcHsMode( ch, DMA_HSMODE_HARDWARE );
    Dma_SetFifoMode( ch, 1 );
    Dma_SetFlowCtrl( ch, 1 );
    Dma_SetHProt( ch, 6 );
    Dma_EnableIsrBit( ch, DMA_INTT_BLOCK );
}
 
static void config_dma_tx( int ch )
{
    Dma_ClearIsrBit(ch,(DMA_INTT_TXR | DMA_INTT_BLOCK | DMA_INTT_SOURCE | DMA_INTT_DEST | DMA_INTT_ERR));// new add
 
    Dma_SetTxrType( ch, DMA_TTFC_M2P_DMAC );
    Dma_SetSrcWidth( ch, DMA_TXR_32BITS );  //DMA_TXR_32BITS
    Dma_SetSrcSize( ch, DMA_BURST_4 );
    Dma_SetDstWidth( ch, ((SPI_UNIT_TR_BITS == 8) ? DMA_TXR_8BITS : DMA_TXR_16BITS));
    Dma_SetDstSize( ch, DMA_BURST_4 );
    Dma_SetSrcIncDirection( ch, DMA_DIR_INC );
    Dma_SetDstIncDirection( ch, DMA_DIR_UNCHG );
    Dma_SetDstHsMode( ch, DMA_HSMODE_HARDWARE );
    Dma_SetFifoMode( ch, 1 );
    Dma_SetFlowCtrl( ch, 1 );
    Dma_SetHProt( ch, 6 );
    Dma_EnableIsrBit( ch, DMA_INTT_BLOCK );
}
int spi_one_cycle_transfer(UINT8 idx,const UINT8 *tx_buff,UINT8 *rx_buff,UINT32 len)
{
    UINT8 ret;
     
//1.wait master pull up ack gpio
    OSSemPend(sem_wifi_ack_gpio, 0, &ret );
//2.pull up slaver ack gpio
    //Gpio_SetPortX(HW_HELP_SPI_GPIO,1);
//3.block to exchange data
    config_spi(g_spi_chan);
    Spi_SetDmaControlEnable( idx, SPI_DMA_RX_POS | SPI_DMA_TX_POS );
    Spi_Enable( g_spi_chan, 1 );
     
 
    //config tx
    config_dma_tx( g_spitx_dma_chan );
    Dma_SetSrcAddress( g_spitx_dma_chan, (unsigned int)tx_buff );
    Dma_SetDstAddress( g_spitx_dma_chan, SPI_DATA_REG );
    Dma_SetDstPer( g_spitx_dma_chan, DMA_HSP_SPI2TX );
    Dma_SetTxrSize( g_spitx_dma_chan, len >> 2 );
    Dma_EnableChan( g_spitx_dma_chan );
     
    //config rx
    config_dma_rx( g_spirx_dma_chan );
    Dma_SetSrcAddress( g_spirx_dma_chan, SPI_DATA_REG );
    Dma_SetDstAddress( g_spirx_dma_chan, (unsigned int)rx_buff );
    Dma_SetSrcPer( g_spirx_dma_chan, DMA_HSP_SPI2RX );
    Dma_SetTxrSize( g_spirx_dma_chan, (SPI_UNIT_TR_BITS == 8) ? len : (len >> 1));
    Dma_EnableChan( g_spirx_dma_chan );
 
     
 
    Gpio_SetPortX(HW_HELP_SPI_GPIO,1);
    OSSemPend(g_dmaSpiRx_done, 0, &ret);    //don't wait forever,need to change
 
//4.pull down slaver ack gpio
    Gpio_SetPortX(HW_HELP_SPI_GPIO,0);
 
    return 0;
 
}
unsigned char slaveRxBuff[1200] = {0};
unsigned char slaveTxBuff[1200] = "123456789123456789"; 
static void _spiFrCCThreadFun(void *param)
{   
    UINT8 ret;
 
 
    sem_wifi_ack_gpio = OSSemCreate(0);
     
    while(1)
    {
//1.check msg queue first.if it have,mean dsp want to send something initiative
     
//2.package data
     
//3.exchange data   
    spi_one_cycle_transfer(g_spi_chan, slaveTxBuff, slaveRxBuff, 600);
    uprintf("_spiFrCCThreadFun slaveRxBuff=%x-%x-%x-%x-%x-%x\n",slaveRxBuff[0],
        slaveRxBuff[1],slaveRxBuff[2],slaveRxBuff[3],slaveRxBuff[4],slaveRxBuff[5]);
//4.unpackage data
     
//5.analysis data
     
    }
}

  • Hi Kevin,

    Have you verified the full buffer is sent on the data line? Try using a logic analyzer. Include waveform in response if possible.

    Jesu
  • Hi Jesu,

    No matter what I set “half of fifo” or "full fifo", this issue always occur. Original buffer is "123456789",  logic analyzer catching shows "12569"(picture 1).

    But, when I change Dma_SetDstWidth from "DMA_TXR_16BITS" to "DMA_TXR_8BITS", logic analyzer catching shows "1 3 5 7 9"(picture 2).

  • Hi Kevin,

    It looks like the problem is FH8610 side because it's not sending out the full buffer for the CC3220. I'm not sure that device works but it seems like your DMA configuration is wrong some how or maybe you need to double clock speed. I am not familiar with the device you're using.

    Jesu
  • Hi Jesu,

    How to modify rxFifoTrigger and txFifoTrigger in CC3220 program(SPICC32XXDMA.c). It seems can't be compiled when I run a spimaster demo.

    /* SPI FIFO trigger sizes vary based on data frame size */
    if (object->dataSize < 9) {
    object->rxFifoTrigger = sizeof(uint8_t);
    object->txFifoTrigger = sizeof(uint8_t);
    }
    else if (object->dataSize < 17) {
    object->rxFifoTrigger = sizeof(uint16_t); //sizeof(uint16_t)
    object->txFifoTrigger = sizeof(uint16_t); //sizeof(uint16_t)
    }
    else {
    object->rxFifoTrigger = sizeof(uint32_t);
    object->txFifoTrigger = sizeof(uint32_t);
    }
  • Hi Jesu,
    This issue that losing spi data was solved!
    WIFI's "csControl" should equal "SPI_SW_CTRL_CS", but no "SPI_HW_CTRL_CS".