This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C I2C SHT30

自己写了一下SHT30温湿度传感器的读取值函数,但是读不上来数呀。大侠,帮忙看看哪的问题。代码如下,先谢谢了

#include <stdint.h>

 #include <stdbool.h>

 #include "inc/hw_ints.h"

 #include "inc/hw_memmap.h"

 #include "inc/hw_types.h"

#include "driverlib/rom.h"

#include "driverlib/pin_map.h"

#include "driverlib/sysctl.h"

 #include "driverlib/systick.h"

#include "driverlib/gpio.h"

#include "driverlib/i2c.h"

#include "sht30_init.h"

#define  i2cAddWrite           0x88

#define  i2cAddRead            0x89

#define CMD_MEAS_PERI_4_HI   0x2334

#define CMD_FETCH_COMM       0xE000

typedef struct {  uint8_t dostate;  

                          uint8_t count;

                           uint8_t putData[6];   }i2c_parameter   i2c0;

void sht30_init(void)

{  

    uint8_t i;

  SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

//  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);  

GPIOPinConfigure(GPIO_PB2_I2C0SCL);   

GPIOPinConfigure(GPIO_PB3_I2C0SDA);   

GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);   

 GPIOPinTypeI2C(GPIO_PORTB_BASE,  GPIO_PIN_3 );  

 I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);

   I2CMasterEnable(I2C0_BASE);   

 for(i=0;i<50;i++)  

 {    SysCtlDelay(SysCtlClockGet()/3000);

 }

}

int read_Periodidata(void)

 {  

uint8_t j,rop;

//写连续读指令0x2334

I2CMasterSlaveAddrSet(I2C0_BASE, i2cAddWrite, false);  

 I2CMasterDataPut(I2C0_BASE, 0x23);  

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);  

while(I2CMasterBusBusy(I2C0_BASE));  

  I2CMasterDataPut(I2C0_BASE, 0x34);  

 I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);  

while(I2CMasterBusBusy(I2C0_BASE));

//开始读取温湿度

I2CMasterSlaveAddrSet(I2C0_BASE, i2cAddWrite, false);

I2CMasterDataPut(I2C0_BASE, 0xe0);  

 I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);  

 while(I2CMasterBusBusy(I2C0_BASE));

I2CMasterDataPut(I2C0_BASE, 0x00);  

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);  

 while(I2CMasterBusBusy(I2C0_BASE));  

 I2CMasterSlaveAddrSet(I2C0_BASE, i2cAddRead, true);  

I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START);

for(j = 0; j < 5; j++)  

 {   

while(I2CMasterBusBusy(I2C0_BASE));  

  i2c0.putData[j] = I2CMasterDataGet(I2C0_BASE);   

 if(j==(5-1))     

 I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);  

  else     

 I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT);

  }  

while(I2CMasterBusBusy(I2C0_BASE));

  rop = I2CMasterErr(I2C0_BASE);

  return rop;

 

 }