AD7606使用模拟SPI无法读取到数据

2019-07-21 02:46发布

MCU为F107,使用模拟SPI
int main(void)
{
        int j;
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
        InitTimer();//配置一个定时器,每间隔500Ms让J-1
        bsp_InitSPIBus();        //初始化SPI总线
        g_tAD7606.Range = 1;        /* 10V */
        bsp_spi_InitAD7606();        //初始化SPI总线意外的连接点
        while (1)
        {
          if (j==1)
                {       
                AD7606_Scan();
                AD7606_Mak();
                j=0;                       
                }
                }
}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
5条回答
whj467467274672
1楼-- · 2019-07-21 05:39
结贴,BUSY没接到AD7606上,接上就好了。
whj467467274672
2楼-- · 2019-07-21 06:15
发现BUSY 长时间高电平,
void AD7606_Scan(void)
{
        uint8_t i;                       

        if (BUSY_IS_LOW())          
    {
                AD_CS_0(); /* SPIƬѡ = 0 */
       
                for (i = 0; i < CH_NUM; i++)
                {
                        s_adc_now[i] = bsp_spiRead1();
                       
                        s_adc_now[i] = s_adc_now[i] * 256 + bsp_spiRead1();       
                }
       
                AD_CS_1();

                AD7606_StartConv();               
        }
}       


void AD7606_Mak(void)
{
        uint8_t i;
        int16_t adc;

        for (i = 0;i < CH_NUM; i++)
        {       
                s_dat[i] = AD7606_ReadAdc(i);
               
                adc = s_dat[i];
                if (g_tAD7606.Range == 0)
                {
                        s_volt[i] = (adc * 5000) / 32767;
                }
                else
                {
                        s_volt[i] = (adc * 10000) / 32767;
                }
        }
}



#ifdef SOFT_SPI               
        GPIO_InitTypeDef  GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_SCK | RCC_MISO, ENABLE);       
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Pin = PIN_SCK;
        GPIO_Init(PORT_SCK, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;       
        GPIO_InitStructure.GPIO_Pin = PIN_MISO;
        GPIO_Init(PORT_MISO, &GPIO_InitStructure);
#endif




static void AD7606_ConfigGPIO(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);               
       
        GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
       

        RCC_APB2PeriphClockCmd(RCC_CS | RCC_RANGE | RCC_BUSY | RCC_RESET | RCC_CONVST, ENABLE);       
       

        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;       

        GPIO_InitStructure.GPIO_Pin = PIN_RESET;
        GPIO_Init(PORT_RESET, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = PIN_CONVST;
        GPIO_Init(PORT_CONVST, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = PIN_RANGE;
        GPIO_Init(PORT_RANGE, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = PIN_CS;
        GPIO_Init(PORT_CS, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;               

        GPIO_InitStructure.GPIO_Pin = PIN_BUSY;
        GPIO_Init(PORT_BUSY, &GPIO_InitStructure);
}

正点原子
3楼-- · 2019-07-21 11:38
 精彩回答 2  元偷偷看……
whj467467274672
4楼-- · 2019-07-21 17:00
本帖最后由 whj467467274672 于 2018-6-3 15:29 编辑

BUSY一直是高电平,板子上的BUSY线没接好,硬件问题。
MAXcrown
5楼-- · 2019-07-21 20:55
学习了,感谢分享。

一周热门 更多>