Skip to content

xgzp 6867 i2c failed to upload sketch to wemos lolin 32 #2432

@Bryanbaring

Description

@Bryanbaring

Hardware:

Board: wemos lolin esp32
Core Installation version: ?1.0.0
IDE name: ?Arduino IDE 1.8.5
Flash Frequency: ?40Mhz

Upload Speed: ?115200?
Computer OS: ?Windows 10

Description:

ibeen stugling for 3mmnths and submission of output is near .my wemos lolin is working find in any file example in arduino ide.. im really sure that i installed properly the esp 32 to arduino ide.. my problem is when im uploading the sketch of my xgzp 6867 pressure sensor . "im getting error compiling sketch for wemos lolin32".. or just dont write it the right . please corrrect my sketch on how to compile it in my wemos lolin 32.. thank you in advance.

//Change the code below by your sketch

#include "LCD1602.h"
#include "Stdio.h"
#include "XGZPC.h"

int main(void)
{
char DisplayBuff[20];
float XGZPC_Data = 100;

LCD_Init();
if(!XGZPC_Init())
	while(1);



LCD_Write_String(0,0,"ZPC:         KPa");
while(1)
{

	
	}
if(Get_XGZPC_Value(&XGZPC_Data))
	{
	  sprintf(DisplayBuff,"%6.2f",XGZPC_Data);
	  LCD_Write_String(5,0,DisplayBuff);
	}
	else
	{
		LCD_Write_String(6,0,"error");
	}
}

}

XGZP6867_Pressure_Sensor_Module[1].pdf

this are the source code for the main ;
#include "XGZPC.h"
#include <intrins.h>

#define _Nop() nop() //¶¨Òå¿ÕÖ¸Áî

sbit I2C_SDA = P1^4;
sbit I2C_SCL = P1^3;

xdata char I2C_DataBuff[6];

//static void I2C_DelayUs2x(unsigned char t)
//{
// while(--t);
//}

//static void I2C_DelayMs(unsigned char t)
//{
//
// while(t--)
// {
// //´óÖÂÑÓʱ1mS
// I2C_DelayUs2x(245);
// I2C_DelayUs2x(245);
// }
//}

/------------------------------------------------
Æô¶¯×ÜÏß
------------------------------------------------
/
static void Start_I2c()
{
I2C_SDA=1; //·¢ËÍÆðʼÌõ¼þµÄÊý¾ÝÐźÅ
_Nop();
I2C_SCL=1;
_Nop(); //ÆðʼÌõ¼þ½¨Á¢Ê±¼ä´óÓÚ4.7us,ÑÓʱ
_Nop();
_Nop();
_Nop();
_Nop();
I2C_SDA=0; //·¢ËÍÆðʼÐźÅ
_Nop(); //ÆðʼÌõ¼þËø¶¨Ê±¼ä´óÓÚ4¦Ì
_Nop();
_Nop();
_Nop();
_Nop();
I2C_SCL=0; //ǯסI2C×ÜÏߣ¬×¼±¸·¢ËÍ»ò½ÓÊÕÊý¾Ý
_Nop();
_Nop();
}
/------------------------------------------------
½áÊø×ÜÏß
------------------------------------------------
/
static void Stop_I2c()
{
I2C_SDA=0; //·¢ËͽáÊøÌõ¼þµÄÊý¾ÝÐźÅ
_Nop(); //·¢ËͽáÊøÌõ¼þµÄʱÖÓÐźÅ
I2C_SCL=1; //½áÊøÌõ¼þ½¨Á¢Ê±¼ä´óÓÚ4¦Ì
_Nop();
_Nop();
_Nop();
_Nop();
_Nop();
I2C_SDA=1; //·¢ËÍI2C×ÜÏß½áÊøÐźÅ
_Nop();
_Nop();
_Nop();
_Nop();
}

/----------------------------------------------------------------
·¢ËÍÊý¾Ý
------------------------------------------------------------------
/
static unsigned char I2C_SendByte(unsigned char Byte)
{
unsigned char i,I2C_ACK;

for(i=0;i<8;i++) //Òª´«Ë͵ÄÊý¾Ý³¤¶ÈΪ8λ
{
if((Byte<<i)&0x80)I2C_SDA=1; //ÅжϷ¢ËÍλ
else I2C_SDA=0;
_Nop();
I2C_SCL=1; //ÖÃʱÖÓÏßΪ¸ß£¬Í¨Öª±»¿ØÆ÷¿ªÊ¼½ÓÊÕÊý¾Ýλ
_Nop();
_Nop(); //±£Ö¤Ê±ÖÓ¸ßµçÆ½ÖÜÆÚ´óÓÚ4¦Ì
_Nop();
_Nop();
_Nop();
I2C_SCL=0;
}

_Nop();
_Nop();
I2C_SDA=1;               //8λ·¢ËÍÍêºóÊÍ·ÅÊý¾ÝÏߣ¬×¼±¸½ÓÊÕÓ¦´ðλ
_Nop();
_Nop();   
I2C_SCL=1;
_Nop();
_Nop();
_Nop();
if(I2C_SDA==1)
  I2C_ACK=0;     
   else 
  I2C_ACK=1;        //ÅжÏÊÇ·ñ½ÓÊÕµ½Ó¦´ðÐźÅ
I2C_SCL=0;
_Nop();
_Nop();
return I2C_ACK;

}

/----------------------------------------------------------------
¶ÁÈ¡Êý¾Ý
------------------------------------------------------------------
/
static unsigned char I2C_RcvByte()
{
unsigned char retc;
unsigned char i;

retc=0;
I2C_SDA=1; //ÖÃÊý¾ÝÏßΪÊäÈ뷽ʽ
for(i=0;i<8;i++)
{
_Nop();
I2C_SCL=0; //ÖÃʱÖÓÏßΪµÍ£¬×¼±¸½ÓÊÕÊý¾Ýλ
_Nop();
_Nop(); //ʱÖÓµÍµçÆ½ÖÜÆÚ´óÓÚ4.7us
_Nop();
_Nop();
_Nop();
I2C_SCL=1; //ÖÃʱÖÓÏßΪ¸ßʹÊý¾ÝÏßÉÏÊý¾ÝÓÐЧ
_Nop();
_Nop();
retc=retc<<1;
if(I2C_SDA==1)retc=retc+1; //¶ÁÊý¾Ýλ,½ÓÊÕµÄÊý¾Ýλ·ÅÈëretcÖÐ
_Nop();
_Nop();
}
I2C_SCL=0;
_Nop();
_Nop();
return(retc);
}

/----------------------------------------------------------------
Ó¦´ð×Óº¯Êý
----------------------------------------------------------------
/
static void Ack_I2c(void)
{

I2C_SDA=0;
_Nop();
_Nop();
_Nop();
I2C_SCL=1;
_Nop();
_Nop(); //ʱÖÓµÍµçÆ½ÖÜÆÚ´óÓÚ4¦Ì
_Nop();
_Nop();
_Nop();
I2C_SCL=0; //ÇåʱÖÓÏߣ¬Ç¯×¡I2C×ÜÏßÒÔ±ã¼ÌÐø½ÓÊÕ
_Nop();
_Nop();
}
/----------------------------------------------------------------
·ÇÓ¦´ð×Óº¯Êý
----------------------------------------------------------------
/
static void NoAck_I2c(void)
{

I2C_SDA=1;
_Nop();
_Nop();
_Nop();
I2C_SCL=1;
_Nop();
_Nop(); //ʱÖÓµÍµçÆ½ÖÜÆÚ´óÓÚ4¦Ì
_Nop();
_Nop();
_Nop();
I2C_SCL=0; //ÇåʱÖÓÏߣ¬Ç¯×¡I2C×ÜÏßÒÔ±ã¼ÌÐø½ÓÊÕ
_Nop();
_Nop();
}

/----------------------------------------------------------------
ÏòÓÐ×ÓµØÖ·Æ÷¼þ·¢ËͶà×Ö½ÚÊý¾Ýº¯Êý
----------------------------------------------------------------
/
bit I2C_SendByteLen(unsigned char DeviceAddress,unsigned char RegAddress,unsigned char *s,unsigned char DataLen)
{
unsigned char i;

Start_I2c(); //Æô¶¯×ÜÏß
if(I2C_SendByte(DeviceAddress) == 0) //·¢ËÍÆ÷¼þµØÖ·
return(0);
if(I2C_SendByte(RegAddress) == 0) //·¢ËÍÆ÷¼þ×ÓµØÖ·
return(0);

for(i=0;i<DataLen;i++)
{
if(I2C_SendByte(*s) == 0) //·¢ËÍÊý¾Ý
return(0);
s++;
}
Stop_I2c(); //½áÊø×ÜÏß
return(1);
}

/----------------------------------------------------------------
ÏòÓÐ×ÓµØÖ·Æ÷¼þ¶ÁÈ¡¶à×Ö½ÚÊý¾Ýº¯Êý
----------------------------------------------------------------
/
bit I2C_RecvByteLen(unsigned char DeviceAddress,unsigned char RegAddress,unsigned char *s,unsigned char DataLen)
{
unsigned char i;

Start_I2c(); //Æô¶¯×ÜÏß
if(I2C_SendByte(DeviceAddress) == 0) //·¢ËÍÆ÷¼þµØÖ·
return(0);
if(I2C_SendByte(RegAddress) == 0) //·¢ËÍÆ÷¼þ×ÓµØÖ·
return(0);

Start_I2c();
if(I2C_SendByte(DeviceAddress+1) == 0)
return(0);

for(i=0;i<DataLen-1;i++)
{
*s=I2C_RcvByte(); //·¢ËÍÊý¾Ý
Ack_I2c(); //·¢Ë;ʹðλ
s++;
}
*s=I2C_RcvByte();
NoAck_I2c(); //·¢ËÍ·ÇӦλ
Stop_I2c(); //½áÊø×ÜÏß
return(1);
}

unsigned char XGZPC_Init(void)
{
I2C_SDA = 1;
I2C_SCL = 1;
if(I2C_RecvByteLen(0xda,0xa5,I2C_DataBuff,1) == 0)
return 0;
I2C_DataBuff[0] &= 0xfd;
if(I2C_SendByteLen(0xda,0xa5,I2C_DataBuff,1) == 0)
return 0;
I2C_DataBuff[0] = 0x0a;
if(!I2C_SendByteLen(0xda,0x30,I2C_DataBuff,1))
return 0;
return 1;
}

unsigned char Get_XGZPC_Value(float *Value)
{
float XGZPC_Value = 0;
if(I2C_RecvByteLen(0xda,0x06,I2C_DataBuff,3))
{
XGZPC_Value = I2C_DataBuff[0] * 65536 + I2C_DataBuff[1] * 256 + I2C_DataBuff[2];
XGZPC_Value = (XGZPC_Value / 8388608) * 100;

// if(XGZPC_Value > 8388608)
// XGZPC_Value = (XGZPC_Value - 16777216) / 8388608 * 8.192;
// else
// XGZPC_Value = XGZPC_Value / 8388608 * 8.192;
*Value = XGZPC_Value;
I2C_DataBuff[0] = 0x0a;
if(!I2C_SendByteLen(0xda,0x30,I2C_DataBuff,1))
return 0;
return 1;
}
return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions