电路图用的这个
没有接VSEN+和VSEN-,引脚仅使用了VAD、VDD、GND、DQ
DQ接的stm32f10xVET6的GPIOC_PIN4引脚
下边是程序,大佬能帮我看看有什么错误吗
#include "stm32f10x.h"
#include "stdio.h"
#include "bsp_usart.h"
#include "yanshi.h"
#include "hong.h"
#define R 0.05
float A,B,C,D,E,F;
float I,J;
u8 ds2438_reset(void);
void ds2438_wr_byte(u8 cmd);
u8 ds2438_rd_byte(void);
void ds2438_initcommand(void);
float Read_Current(void);
float Read_Temperature(void);
float Read_Voltage(void);
float Read_ICAcurrent(void);
float Read_CCAcurrent(void);
float Read_DCAcurrent(void);
void ds2438_test(void);
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOC, &GPIO_InitStructure);
CH4;
delay_ms(10);
ds2438_initcommand();
USART_Config();
while (1)
{
ds2438_test();
printf("\r\n The current value = %f \r\n",C);
printf("\r\n The Voltage value = %f \r\n",B);
delay_ms(1000);
C=0;
B=0;
}
}
u8 ds2438_reset(void) //由主机发送复位信号,然后用presence去接2438给的应答信号,如果presence接到了0,说明2438有应答
{
u8 presence;
CL4;
delay_us(500);
CH4;
delay_us(30);
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4)==1) {presence = 1;}
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_4)==0) {presence = 0;}
delay_us(300);
return