ADE9078 SPI通讯

您好! 使用IO口模拟SPI与ADE9078通讯,参考软件代码为贵公司推荐的软件代码(附件1 SimuSPI.C),自写代码为附件2(SPI_IO.c)。用示波器测试时钟信号,MOSI输出信号正常,但ADE9078通过SOMI反馈回的值在CLK总线上没有时钟信号时一直为高电平(1),有时钟信号时发送读指令后返回0(主程序为main.c,读取Ox4FE寄存器的版本号,默认为0x0040),不解,是没有通讯上吗?求解答。注:示波器中蓝线为CLK,黄线为MOSI,粉线为SOMI




[edited by: ternence at 1:25 AM (GMT -5) on 1 Mar 2021]
  • 	main.c
    	ADE_WriteBytes(ADDR_RUN,1);//启动测量
    	ADE_WriteBytes(ADDR_EP_CFG,1);//启动电能功率累计
    	uint32_t data=0,data1=0;
        while(1) 
        {
        
    				data = ADE_ReadBytes(ADDR_VERSION);
    
    				printf("data=%x\n",data);
    
    	}
    
        	
    demo:
    void Read_ADE9000_SPI(uint16_t  us_ADE_Addr, uint16_t us_Nr_Bytes, uint8_t *puc_Reg_Data)
    {
    	uint16_t us_iCounter;
    	uint16_t us_iAddress; 
    	uint8_t *puc_TempData;
    	uint8_t  uc_LS_Addr,uc_MS_Addr;
    
    	us_iAddress = us_ADE_Addr;
    	us_iAddress = (us_iAddress << 4);
    	us_iAddress = (us_iAddress | 0x08);
    	puc_TempData = puc_Reg_Data;
    
      	uc_LS_Addr = (uint8_t) us_iAddress;
    	uc_MS_Addr =(uint8_t) (us_iAddress >> 8);
    	
    	SPI_Delay(ADE9000_Start_Delay_Value); 
    	Enable_ADE_CS;	
    	SPI_Delay(ADE9000_Start_Delay_Value); 
    
    	SPI_MCUWriteByte(uc_MS_Addr);
    
    	
    	//send LS byte of address
    	SPI_MCUWriteByte(uc_LS_Addr);
    
    	High_ADE_MOSI;
    	//ADE90xx comm data format: MSB--LSB ; So need send out the MSB first.
    	puc_TempData=puc_TempData+(us_Nr_Bytes-1);
    
    	for (us_iCounter=0;us_iCounter<us_Nr_Bytes;us_iCounter++)
    	{
    		*puc_TempData=SPI_MCUReadByte();
    		puc_TempData--;
    	 }
    	High_ADE_MOSI;
    	Disable_ADE_CS;;
    	SPI_Delay(ADE9000_Comu_Delay_Value);  
    	//enable back the interrupts because the communcation has finished
    	//__enable_interrupt();
    	
    }
    static void SPI_MCUWriteByte(unsigned char wByte) 
    { 
            unsigned char i;  
    
            for(i=0;i<8;i++) 
            {  
                    if((wByte<<i)&0x80){High_ADE_MOSI;}  
                    else{Low_ADE_MOSI;}  
    
                    Low_ADE_SCLK;
                    SPI_Delay(ADE9000_Comu_Delay_Value);  
                    High_ADE_SCLK;  
    				SPI_Delay(ADE9000_Comu_Delay_Value);  
            }  
    } 
    my code:
    uint32_t ADE_ReadBytes(uint16_t address)
    {
    	uint16_t rcmd;
    	uint32_t data = 0;
    
    	uint8_t wdh,wdl;
    	
    	rcmd = (address << 4) | 0x0008;//������
    
    	wdh = rcmd >> 8;
    	wdl = rcmd;
    	DELAY_US(10);
    	//printf ("cmd=%d\n",rcmd);
    	ADE_CSLOW();
    	DELAY_US(10);
    	//IO_write8Bytes(wdh);//
    	
    	//IO_write8Bytes(wdl);//
    	IO_write16Bytes(rcmd);
    
    	/*if(address >= 0x480 && address <= 0x4FE)
    	{
    		data = IO_read16Bytes();
    	}
    	else
    	{
    		data = IO_read32Bytes();
    	}*/
    	
    	ADE_MOSIHIGH();
    	data = IO_read8Bytes();
    	ADE_MOSIHIGH();
    	
    	DELAY_US(10);
    	ADE_CSHIGH();
    	DELAY_US(10);
    	return data;
    	
    }
    void IO_write16Bytes(uint16_t word)
    {
    	int i;
    	Uint16 tem,result = 0;
    
    	for(i=0;i<16;i++)
    	{
    
    		tem = word << i;
    		result = tem & 0x8000;
    		
    		if(result == 0x8000)//MSB
    		{
    			ADE_MOSIHIGH();
    			//printf("1\n");
    	
    		}
    		else
    		{
    			ADE_MOSILOW();
    			//printf("0\n");
    		
    		}
    		ADE_CLKLOW();//
    		DELAY_US(10);//相当于100K波特率
    		ADE_CLKHIGH();
    		DELAY_US(10);
    		
    		
    	}
    	//printf("d\n");
    
    	
    
    	
    	
    }

  • 0
    •  Analog Employees 
    on Feb 24, 2021 1:48 AM 7 days ago
    1. 请确认ADE9078正常复位,可以在上电后测试AVDDDVDD引脚是否正常;
    2. 请确认CS引脚的波形是否正常;
    3. 请确认读写的寄存器内容;