SPL06-001与SPL06-007的区别及驱动程序

SPL06-001与SPL06-007的区别及驱动程序

网上搜了好久,关于这两个芯片的资料很少,对比发现两个只相差SPI驱动,SPL06-001只有IIC方式驱动,SPL06-007多了一个SPI驱动方式 ,其它完全一样。
画封装的时候注意那个外壳上的气孔与底板的MARK点不是同一个位置,而且在对角位置上,千万不要搞错了。在这里插入图片描述
放置的位置注意不要靠近发热大的芯片周围,否则测量的就是板上的温度,高很多,有条件的可以在周围开隔离孔,
软件上如果是用IIC驱动两者是一样的,github有个库写的很好,直接使用

https://github.com/rv701/SPL06-007/blob/master/src/SPL06-007.cpp

SPL06-007.h文件

#include "Arduino.h"
void SPL_init();

uint8_t get_spl_id();		// Get ID Register 		0x0D
uint8_t get_spl_prs_cfg();	// Get PRS_CFG Register	0x06
uint8_t get_spl_tmp_cfg();	// Get TMP_CFG Register	0x07
uint8_t get_spl_meas_cfg();	// Get MEAS_CFG Register	0x08
uint8_t get_spl_cfg_reg();	// Get CFG_REG Register	0x09
uint8_t get_spl_int_sts();	// Get INT_STS Register	0x0A
uint8_t get_spl_fifo_sts();	// Get FIFO_STS Register	0x0B

double get_altitude(double pressure, double seaLevelhPa);	// get altitude in meters
double get_altitude_f(double pressure, double seaLevelhPa);	// get altitude in feet

int32_t get_traw();
double get_traw_sc();
double get_temp_c();
double get_temp_f();
double get_temperature_scale_factor();

int32_t get_praw();
double get_praw_sc();
double get_pcomp();
double get_pressure_scale_factor();
double get_pressure();

int16_t get_c0();
int16_t get_c1();
int32_t get_c00();
int32_t get_c10();
int16_t get_c01();
int16_t get_c11();
int16_t get_c20();
int16_t get_c21();
int16_t get_c30();

void i2c_eeprom_write_uint8_t(  uint8_t deviceaddress, uint8_t eeaddress, uint8_t data );
uint8_t i2c_eeprom_read_uint8_t(  uint8_t deviceaddress, uint8_t eeaddress );

SPL06-007.cpp文件

`#include "SPL06-007.h"
#include "Wire.h"

uint8_t SPL_CHIP_ADDRESS = 0x76;

void SPL_init()
{
	i2c_eeprom_write_uint8_t(SPL_CHIP_ADDRESS, 0X06, 0x03);	// Pressure 8x oversampling

	i2c_eeprom_write_uint8_t(SPL_CHIP_ADDRESS, 0X07, 0X83);	// Temperature 8x oversampling

	i2c_eeprom_write_uint8_t(SPL_CHIP_ADDRESS, 0X08, 0B0111);	// continuous temp and pressure measurement

	i2c_eeprom_write_uint8_t(SPL_CHIP_ADDRESS, 0X09, 0X00);	// FIFO Pressure measurement  
}

uint8_t get_spl_id()
{
	return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x0D);	
}

uint8_t get_spl_prs_cfg()
{
	return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x06);
}

uint8_t get_spl_tmp_cfg()
{
	return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x07);
}

uint8_t get_spl_meas_cfg()
{
	return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x08);
}

uint8_t get_spl_cfg_reg()
{
	return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x09);
}

uint8_t get_spl_int_sts()
{
	return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x0A);
}

uint8_t get_spl_fifo_sts()
{
	return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x0B);
}



double get_altitude(double pressure, double seaLevelhPa) {
	double altitude;

	altitude = 44330 * (1.0 - pow(pressure / seaLevelhPa, 0.1903));

	return altitude;
}

double get_altitude_f(double pressure, double seaLevelhPa)
{
	double altitude;

	altitude = 44330 * (1.0 - pow(pressure / seaLevelhPa, 0.1903));

	return altitude * 3.281;
}


double get_traw_sc()
{
	int32_t traw = get_traw();
	return (double(traw)/get_temperature_scale_factor());
}


double get_temp_c()
{
	int16_t c0,c1;
	c0 = get_c0();
	c1 = get_c1();
	double traw_sc = get_traw_sc();
	return (double(c0) * 0.5f) + (double(c1) * traw_sc);
}


double get_temp_f()
{
	int16_t c0,c1;
	c0 = get_c0();
	c1 = get_c1();
	double traw_sc = get_traw_sc();
	return (((double(c0) * 0.5f) + (double(c1) * traw_sc)) * 9/5) + 32;
}


double get_temperature_scale_factor()
{
  
  double k;

  uint8_t tmp_Byte;
  tmp_Byte = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X07); // MSB

  //Serial.print("tmp_Byte: ");
  //Serial.println(tmp_Byte);

  //tmp_Byte = tmp_Byte >> 4; //Focus on bits 6-4
  tmp_Byte = tmp_Byte & 0B00000111;
  //Serial.print("tmp_Byte: ");
  //Serial.println(tmp_Byte);

  switch (tmp_Byte) 
  {
    case 0B000:
      k = 524288.0;
    break;

    case 0B001:
      k = 1572864.0;
    break;

    case 0B010:
      k = 3670016.0;
    break;

    case 0B011:
      k = 7864320.0;
    break;

    case 0B100:
      k = 253952.0;
    break;

    case 0B101:
      k = 516096.0;
    break;

    case 0B110:
      k = 1040384.0;
    break;

    case 0B111:
      k = 2088960.0;
    break;
  }

  return k;
}


int32_t get_traw()
{
  int32_t tmp;
  uint8_t tmp_MSB,tmp_LSB,tmp_XLSB;
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X03); // MSB

  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X04); // LSB

  tmp_XLSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X05); // XLSB

  tmp = (tmp_MSB << 8) | tmp_LSB;
  tmp = (tmp << 8) | tmp_XLSB;


  if(tmp & (1 << 23))
    tmp = tmp | 0XFF000000; // Set left bits to one for 2's complement conversion of negitive number
  
  
  return tmp;
}

double get_praw_sc()
{
	int32_t praw = get_praw();
	return (double(praw)/get_pressure_scale_factor());
}

double get_pcomp()
{
	int32_t c00,c10;
	int16_t c01,c11,c20,c21,c30;
	c00 = get_c00();
	c10 = get_c10();
	c01 = get_c01();
	c11 = get_c11();
	c20 = get_c20();
	c21 = get_c21();
	c30 = get_c30();
	double traw_sc = get_traw_sc();
	double praw_sc = get_praw_sc();
	return double(c00) + praw_sc * (double(c10) + praw_sc * (double(c20) + praw_sc * double(c30))) + traw_sc * double(c01) + traw_sc * praw_sc * ( double(c11) + praw_sc * double(c21));
}

double get_pressure()
{
	double pcomp = get_pcomp();
	return pcomp / 100; // convert to mb
}



double get_pressure_scale_factor()
{
	double k;

	uint8_t tmp_Byte;
	tmp_Byte = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X06); // MSB

	tmp_Byte = tmp_Byte & 0B00000111; // Focus on 2-0 oversampling rate 


	switch (tmp_Byte) // oversampling rate
	{
		case 0B000:
			k = 524288.0;
		break;

		case 0B001:
			k = 1572864.0;
		break;

		case 0B010:
			k = 3670016.0;
		break;

		case 0B011:
			k = 7864320.0;
		break;

		case 0B100:
			k = 253952.0;
		break;

		case 0B101:
			k = 516096.0;
		break;

		case 0B110:
			k = 1040384.0;
		break;

		case 0B111:
			k = 2088960.0;
		break;
	}

	return k;
}




int32_t get_praw()
{
  int32_t tmp;
  uint8_t tmp_MSB,tmp_LSB,tmp_XLSB;
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X00); // MSB


  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X01); // LSB


  tmp_XLSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X02); // XLSB

  
  tmp = (tmp_MSB << 8) | tmp_LSB;
  tmp = (tmp << 8) | tmp_XLSB;



  if(tmp & (1 << 23))
    tmp = tmp | 0XFF000000; // Set left bits to one for 2's complement conversion of negitive number
  
  
  return tmp;
}

int16_t get_c0()
{
  int16_t tmp; 
  uint8_t tmp_MSB,tmp_LSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X10); 
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X11); 



  tmp_LSB = tmp_LSB >> 4;


  tmp = (tmp_MSB << 4) | tmp_LSB;

  if(tmp & (1 << 11)) // Check for 2's complement negative number
    tmp = tmp | 0XF000; // Set left bits to one for 2's complement conversion of negitive number
  
  return tmp;
}


int16_t get_c1()
{
  int16_t tmp; 
  uint8_t tmp_MSB,tmp_LSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X11); 
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X12); 


  tmp_MSB = tmp_MSB & 0XF;


  tmp = (tmp_MSB << 8) | tmp_LSB;

  if(tmp & (1 << 11)) // Check for 2's complement negative number
    tmp = tmp | 0XF000; // Set left bits to one for 2's complement conversion of negitive number
  
  return tmp;
}

int32_t get_c00()
{
  int32_t tmp; 
  uint8_t tmp_MSB,tmp_LSB,tmp_XLSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X13); 
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X14); 
  tmp_XLSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X15);


  
  tmp_XLSB = tmp_XLSB >> 4;

   
  tmp = (tmp_MSB << 8) | tmp_LSB;
  tmp = (tmp << 4) | tmp_XLSB;

  tmp = (uint32_t)tmp_MSB << 12 | (uint32_t)tmp_LSB << 4 | (uint32_t)tmp_XLSB >> 4;

  if(tmp & (1 << 19))
    tmp = tmp | 0XFFF00000; // Set left bits to one for 2's complement conversion of negitive number
    

  return tmp;
}

int32_t get_c10()
{
  int32_t tmp; 
  uint8_t tmp_MSB,tmp_LSB,tmp_XLSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X15); // 4 bits
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X16); // 8 bits
  tmp_XLSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X17); // 8 bits


  tmp_MSB = tmp_MSB & 0b00001111;



  tmp = (tmp_MSB << 4) | tmp_LSB;
  tmp = (tmp << 8) | tmp_XLSB;



  tmp = (uint32_t)tmp_MSB << 16 | (uint32_t)tmp_LSB << 8 | (uint32_t)tmp_XLSB;

  if(tmp & (1 << 19))
    tmp = tmp | 0XFFF00000; // Set left bits to one for 2's complement conversion of negitive number

  return tmp;
}



int16_t get_c01()
{
  int16_t tmp; 
  uint8_t tmp_MSB,tmp_LSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X18); 
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X19); 

  tmp = (tmp_MSB << 8) | tmp_LSB;
  return tmp;
}

int16_t get_c11()
{
  int16_t tmp; 
  uint8_t tmp_MSB,tmp_LSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1A); 
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1B); 

  tmp = (tmp_MSB << 8) | tmp_LSB;
  return tmp;
}

int16_t get_c20()
{
  int16_t tmp; 
  uint8_t tmp_MSB,tmp_LSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1C); 
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1D); 


  tmp = (tmp_MSB << 8) | tmp_LSB;
  return tmp;
}

int16_t get_c21()
{
  int16_t tmp; 
  uint8_t tmp_MSB,tmp_LSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1E); 
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1F); 

  tmp = (tmp_MSB << 8) | tmp_LSB;
  return tmp;
}

int16_t get_c30()
{
  int16_t tmp; 
  uint8_t tmp_MSB,tmp_LSB;
  
  tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X20); 
  tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X21); 

  tmp = (tmp_MSB << 8) | tmp_LSB;
  return tmp;
  Serial.print("tmp: ");
  Serial.println(tmp);
}

void i2c_eeprom_write_uint8_t(  uint8_t deviceaddress, uint8_t eeaddress, uint8_t data ) 
{
    uint8_t rdata = data;
    delay(5); // Make sure to delay log enough for EEPROM I2C refresh time
    Wire.beginTransmission(deviceaddress);
    Wire.write((uint8_t)(eeaddress));
    Wire.write(rdata);
    Wire.endTransmission();
}



uint8_t i2c_eeprom_read_uint8_t(  uint8_t deviceaddress, uint8_t eeaddress ) 
{
    uint8_t rdata = 0xFF;
    Wire.beginTransmission(deviceaddress);
    Wire.write(eeaddress); 
    Wire.endTransmission(false); // false to not release the line
    
    Wire.requestFrom(deviceaddress,1);
    if (Wire.available()) rdata = Wire.read();
    return rdata;
}

使用非常简单

#include <Wire.h>


void setup() {
  Wire.begin();    // begin Wire(I2C)
  Serial.begin(115200); // begin Serial

  Serial.println("\nGoertek-SPL06-007 Demo\n");

  SPL_init(); // Setup initial SPL chip registers   
}

void loop() {

  // ---- Register Values ----------------
  Serial.print("ID: ");
  Serial.println(get_spl_id());

  Serial.print("PRS_CFG: ");
  Serial.println(get_spl_prs_cfg(),BIN);

  Serial.print("TMP_CFG: ");
  Serial.println(get_spl_tmp_cfg(),BIN);

  Serial.print("MEAS_CFG: ");
  Serial.println(get_spl_meas_cfg(),BIN);

  Serial.print("CFG_REG: ");
  Serial.println(get_spl_cfg_reg(),BIN);

  Serial.print("INT_STS: ");
  Serial.println(get_spl_int_sts(),BIN);

  Serial.print("FIFO_STS: ");
  Serial.println(get_spl_fifo_sts(),BIN);


  // ---- Coefficients ----------------
  Serial.print("c0: ");
  Serial.println(get_c0());

  Serial.print("c1: ");
  Serial.println(get_c1());

  Serial.print("c00: ");
  Serial.println(get_c00());

  Serial.print("c10: ");
  Serial.println(get_c10());

  Serial.print("c01: ");
  Serial.println(get_c01());

  Serial.print("c11: ");
  Serial.println(get_c11());
  
  Serial.print("c20: ");
  Serial.println(get_c20());
  
  Serial.print("c21: ");
  Serial.println(get_c21());

  Serial.print("c30: ");
  Serial.println(get_c30());


  // ---- Temperature Values ----------------  
  Serial.print("traw: ");
  Serial.println(get_traw());

  Serial.print("traw_sc: ");
  Serial.println(get_traw_sc(),3);
  
  Serial.print("Temperature: ");
  Serial.print(get_temp_c());
  Serial.println(" C");
  
  Serial.print("Temperature: ");
  Serial.print(get_temp_f());
  Serial.println(" F");
  

  // ---- Pressure Values ----------------
  Serial.print("praw: ");
  Serial.println(get_praw());
  
  Serial.print("praw_sc: ");
  Serial.println(get_praw_sc(),3);

  Serial.print("pcomp: ");
  Serial.println(get_pcomp(),2);

  Serial.print("Measured Air Pressure: ");
  Serial.print(get_pressure(),2);
  Serial.println(" mb");


  // ---- Altitude Values ----------------
  double local_pressure = 1011.3; // Look up local sea level pressure on google // Local pressure from airport website 8/22
  Serial.print("Local Airport Sea Level Pressure: ");
  Serial.print(local_pressure,2);
  Serial.println(" mb");
  
  Serial.print("altitude: ");
  Serial.print(get_altitude(get_pressure(),local_pressure),1);
  Serial.println(" m");

  Serial.print("altitude: ");
  Serial.print(get_altitude_f(get_pressure(),local_pressure),1); // convert from meters to feet
  Serial.println(" ft");



  Serial.println("\n");
  delay(2000);
}


![在这里插入图片描述](https://img-blog.csdnimg.cn/e9b96badda204e8f9e5d53f895e97736.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA55-l6KGM5pm66YCg5bGA,size_20,color_FFFFFF,t_70,g_se,x_16)

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: 根据我的理解,您的问题是关于spl06-001驱动代码的。这是一个涉及嵌入式系统开发的问题。SPL06-001是一种气压传感器,它可以测量大气压力并将结果转换为数字信号。驱动代码负责将传感器输出的信号转换为有用的数据,并将其传送给应用程序。 在解决这个问题之前,首先需要确定问题的具体表现。如果传感器无法正常工作,则需要检查硬件和连接,以确保它们的正确性。如果硬件和连接都没有问题,那么就需要检查驱动代码本身。 通常,驱动代码问题可能出现在以下几个方面: 1. 源代码错误:驱动代码可能存在语法错误或逻辑错误,导致程序无法正常工作。在这种情况下,需要检查代码并纠正错误。 2. 编译错误:代码可以编译,但在运行时,存在一些错误。这些错误可能是由于编译器版本的问题或者由于缺乏必要的库文件所致。在这种情况下,需要检查编译器和库文件,并更正任何错误。 3. 配置错误:如果代码无法正确配置传感器,那么可能是因为它没有正确的寄存器设置或其他配置错误。在这种情况下,需要仔细查看传感器数据手册,并更正任何配置错误。 综上所述,spl06-001驱动代码问题可能是由多种因素引起的。为了解决这个问题,需要进行一系列的测试和分析,以确定出错的原因,然后采取适当的措施来纠正它。 ### 回答2: spl06-001是一种数字气压计,是一种高精度的传感器,主要用于测量大气压力,并可提供高精度温度测量。驱动代码的问题可能涉及到代码的编写质量、代码中的错误和缺陷、驱动硬件的兼容性等。 首先,驱动代码本身的编写质量是影响spl06-001稳定性和精度的一个重要因素。如果程序员没有遵循正确的编程规范和标准,很可能会导致代码出现错误和漏洞,从而影响spl06-001的功能和表现。 其次,驱动代码与硬件的兼容性也非常关键。如果驱动程序无法与spl06-001所依赖的硬件兼容,则可能会出现无法工作或不稳定的情况。 最后,驱动代码中可能存在的错误和缺陷可能会导致spl06-001的性能下降,增加误差和噪声。因此,必须对这些问题进行及时的检测和修复,以保证spl06-001的可靠性和精度。 总之,spl06-001驱动代码的问题涉及到诸多方面,需要开发者充分地了解硬件设备,遵循正确的编程规范和标准,以及对代码进行充分的测试和修复,从而保证其稳定性和精度。 ### 回答3: spl06-001是一款数字压力传感器,驱动代码的问题可能会影响到其工作效果。驱动代码问题的一种可能是与传感器接口的代码问题,例如连接传感器的I2C总线或SPI总线的代码出现问题,导致传感器无法被正确传输数据。另外,驱动代码可能会出现寄存器设置不正确的问题,导致传感器无法正确解析数据或者输出正确的压力值。同时,驱动代码中也可能存在对传感器特性不了解或者实现错误的情况,例如没有正确地去抵消传感器温度或者压力对输出结果的影响,造成测量精度下降。此外,还有可能存在传感器与处理器接口不匹配的情况,需要根据具体情况进行适配。总之,驱动代码问题需要仔细排查,通过对接口、寄存器设置、传感器特性等方面的调试,逐步解决问题,确保传感器的准确测量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值