微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 硬件电路设计 > 硬件电路设计讨论 > 4线spi调试

4线spi调试

时间:12-12 整理:3721RD 点击:
如图所以 一个硬件的SPA读写时序,小弟写了如下单片机程序去调试SPI读写,貌似写函数是对的,但是每次读函数读的有些问题,和我写的不一样,跪求高手帮我看一下,时序图见附件,代码如下:
void SD_SPI_WriteByte(unsigned char ucSendData)//for ADRF6516
{
    unsigned char ucCount;
    unsigned char ucMaskCode;
    
    SPI_LE = 0;
    SPI_CLK =0;
    Delay_Short();
    Delay_Short();
    SPI_data = 1;
    Delay_Short();
    Delay_Short();
    
    SPI_CLK =1;
    Delay_Short();
    ucMaskCode=0x01;
    for(ucCount=0;ucCount<8;ucCount++)
    {
        SPI_CLK =0;
        if(ucMaskCode&ucSendData)
        {
            SPI_data = 1;
            //Delay_Short();
        }
        else
        {
            SPI_data = 0;
            //Delay_Short();
        }
        
        //SPI_CLK =0;
        Delay_Short();
        Delay_Short();
        Delay_Short();
        SPI_CLK =1;
        ucMaskCode<<=1;
    }
    Delay_Short();
    Delay_Short();
    SPI_CLK =0;
    SPI_LE = 1;
    SPI_data = 0;
}
#if 1
unsigned char SD_SPI_ReadByte(void)//for ADRF6516 not use
{
    unsigned char ucReadData;
    unsigned char ucCount;
    SPI_LE = 0;
    SPI_SDO =1;
    SPI_CLK =0;
    Delay_Short();
    Delay_Short();
    SPI_data = 0;
    Delay_Short();
    Delay_Short();
    SPI_CLK =1;
    Delay_Short();
    Delay_Short();
    
    SPI_CLK =0;
    Delay_Short();
    Delay_Short();
    
    ucReadData=0;
    for(ucCount=0;ucCount<8;ucCount++)
    {
        //Delay_Short();
        //ucReadData >>=1;
        SPI_CLK =1;
        Delay_Short();
        
        if(SPI_SDO)
        {
           // ucReadData|=0x01;
            ucReadData = ucReadData | (0x01<<ucCount);
            
        }
        else
        {
            ucReadData = ucReadData & 0xff;
            Delay_Short();
            Delay_Short();
        }
      
        SPI_CLK =0;
        Delay_Short();
        Delay_Short();
      
      
    }
    Delay_Short();
    Delay_Short();
    
    
    SPI_CLK =1;
    SPI_LE = 1;
    SPI_data = 0;
    return (ucReadData);
}
#endif

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top