有個MPL3115A2氣壓海拔傳感器的資料讀取問題想請問下各位大佬。在配置完IIC后,使用邏輯分析儀抓波形是正常的。但是讀取暫存器(0x00 0x01 0x02 0x03 0x04)的時候回傳來的值都是0xEE。使用仿真除錯的時候,讀取到的幾個暫存器的值先是0x0E,然后過很短一段時間就變成0xEE(是同時改變的),后面從暫存器讀出的值就保持是0xEE了.根據手冊傳感器寫地址使用0xC0,讀地址使用0xC1,按照網上教程初始化了。還望各位大佬指教一下,萬分感謝!
在網上查看類似的問題是回傳0xFF,基本都是IIC配置的問題。回傳0xEE有點看不明白,會不會可能是寫完第一個暫存器讀取值后,后面的其他暫存器讀取都沒有讀到,而是讀到第一個暫存器的值。有沒有使用過這個模塊的大佬~


這是初始化和讀取的代碼:
/**********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;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/74188.html
標籤:單片機/工控
