27,520
社区成员
发帖
与我相关
我的任务
分享

/**********no fifo/polling************/
static uint8_t LocalStatus;
void altiude_data_read(uint8_t *DataBuf)
{
LocalStatus=iic_read_reg(0x06);
if((LocalStatus & 0x08)==0x08)
{
* DataBuf = iic_read_reg(0x01); //altitude
*(DataBuf+1) = iic_read_reg(0x02);
*(DataBuf+2) = iic_read_reg(0x03);
*(DataBuf+3) = iic_read_reg(0x04); //temperature
*(DataBuf+4) = iic_read_reg(0x05);
}
LocalStatus=0;
}
void MPL3115A_Init(void)
{
iic_write_reg(0x11,0x01);
iic_write_reg(0x26,0x04);
iic_write_reg(0x26,0xb9);
iic_write_reg(0x13,0x07);
}
/*iic读写传感器*/
void iic_write_reg(uint8_t write_address, uint8_t SendByte)
{
IIC_Start();
IIC_Send_Byte(SLAVE_WRITE_ADDR); //发送器件地址0XC0,写数据。
IIC_Wait_Ack();
IIC_Send_Byte(write_address); //发送写入数据的目的地址。
IIC_Wait_Ack();
IIC_Send_Byte(SendByte); //发送字节
IIC_Wait_Ack();
IIC_Stop(); //产生一个停止条件
delay_us(1000);
}
uint8_t iic_read_reg(uint8_t read_address)
{
uint8_t temp=0;
IIC_Start();
IIC_Send_Byte(SLAVE_WRITE_ADDR); //发送器件地址0XC0,写数据
IIC_Wait_Ack();
IIC_Send_Byte(read_address); //发送开始读数的地址
IIC_Wait_Ack();
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_11, GPIO_PIN_RESET);
IIC_Start();
IIC_Send_Byte(SLAVE_READ_ADDR); //进入接收模式
IIC_Wait_Ack();
temp=IIC_Read_OneByte();
IIC_Stop(); //产生一个停止条件
return temp;
}哥们后面找到问题了吗