初级会员
- 积分
- 51
- 金钱
- 51
- 注册时间
- 2019-4-26
- 在线时间
- 15 小时
|
3金钱
芯片:FH8610
系统:ucos
SPI参数:位宽16bit,时钟6.75MHz,极性0,相位0
问题:该芯片(从机)与wifi模块(主机)进行SPI通信时,原本要发送buf是“123456789123456789”,但实际测到的却是“1256914589”,也就是每发2字节就丢了2字节,但接收来自WiFi的数据却是正常的。
[mw_shl_code=c,true]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
#if 0
Spi_WriteReadBlock(idx,tx_buff,rx_buff,len);
#else
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
#endif
//4.pull down slaver ack gpio
Gpio_SetPortX(HW_HELP_SPI_GPIO,0);
return 0;
}
static void _spiFrCCThreadFun(void *param)
{
static unsigned char slaveRxBuff[1200] = {0};
static unsigned char slaveTxBuff[1200] = "hellothisisfh8610";
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
}
}[/mw_shl_code]
|
最佳答案
查看完整内容[请看2#楼]
找到问题原因了,是wifi主机CS脚控制参数设置不当导致的,csControl应该为SPI_SW_CTRL_CS,而不是SPI_HW_CTRL_CS,之前还一直以为是DMA的问题。。。
|