CH582 2線SPI主機(jī)通訊問題求助!
void?SPI0_MasterDefInit(void)
{
????R8_SPI0_CLOCK_DIV?=?64;?//?主頻時(shí)鐘4分頻
????R8_SPI0_CTRL_MOD?=?RB_SPI_ALL_CLEAR;
????R8_SPI0_CTRL_MOD?=?RB_SPI_SCK_OE?|?RB_SPI_MST_SCK_MOD;
????R8_SPI0_CTRL_CFG?|=?RB_SPI_AUTO_IF;?????//?訪問BUFFER/FIFO自動(dòng)清除IF_BYTE_END標(biāo)志
????R8_SPI0_CTRL_CFG?&=?~RB_SPI_DMA_ENABLE;?//?不啟動(dòng)DMA方式
}
void?SPI0_Recv_nByte(uint8_t?*pbuf,?uint16_t?len)
{
????uint16_t?readlen;

????readlen?=?len;
????R32_PB_DIR?&=?~GPIO_Pin_15;
????R8_SPI0_CTRL_MOD?|=?RB_SPI_FIFO_DIR;?//?設(shè)置數(shù)據(jù)方向?yàn)檩斎?
????R8_SPI0_CTRL_MOD?&=?~RB_SPI_MISO_OE;?//禁止MISO輸出
????R16_SPI0_TOTAL_CNT?=?len;????????????//?設(shè)置需要接收的數(shù)據(jù)長度,F(xiàn)IFO方向?yàn)檩斎腴L度不為0則會(huì)啟動(dòng)傳輸?*/
????R8_SPI0_INT_FLAG?=?RB_SPI_IF_CNT_END;
????while(readlen)
????{
????????if(R8_SPI0_FIFO_COUNT)
????????{
????????????*pbuf?=?R8_SPI0_FIFO;
????????????pbuf++;
????????????readlen--;
????????}
????}
}
void?SPI0_Send_nByte(uint8_t?*pbuf,?uint16_t?len)
{
????uint16_t?sendlen;

????sendlen?=?len;
????R32_PB_DIR?|=?GPIO_Pin_15;
????R8_SPI0_CTRL_MOD?&=?~RB_SPI_FIFO_DIR;?//?設(shè)置數(shù)據(jù)方向?yàn)檩敵?
????R8_SPI0_CTRL_MOD?|=?RB_SPI_MISO_OE;
????R16_SPI0_TOTAL_CNT?=?sendlen;?????????//?設(shè)置要發(fā)送的數(shù)據(jù)長度
????R8_SPI0_INT_FLAG?=?RB_SPI_IF_CNT_END;
????while(sendlen)
????{
????????if(R8_SPI0_FIFO_COUNT?<?SPI_FIFO_SIZE)
????????{
????????????R8_SPI0_FIFO?=?*pbuf;
????????????pbuf++;
????????????sendlen--;
????????}
????}
????while(R8_SPI0_FIFO_COUNT?!=?0);?//?等待FIFO中的數(shù)據(jù)全部發(fā)送完成
}

以上三個(gè)函數(shù)是我跟庫函數(shù)修改,請幫忙看看邏輯是否有問題,現(xiàn)在無法正常通訊。

結(jié)下貼,因?yàn)橛玫氖荕ISO_引腳,所以需要引腳重映射一下。GPIOPinRemap(ENABLE, RB_PIN_SPI0);


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频