我正在尝试通过德州仪器(TI)的MSP430读取SDP610传感器压差传感器。我遇到的问题是传感器无法确认命令,因此无法传达压力值本身。请注意,我已经确认传感器可以通过开源库将其连接到arduino上,并且可以通过它查看数据。请注意,我的IDE是代码编写器。我的芯片是MSP430FR2311(启动板分支板)。
我的硬件设置为4线。 Vcc(3.3V),Ground(0V),SDK和SCL。根据规范,SDK和SCL线使用4.7Kohm电阻上拉至VCC。
我的MSP430具有以下代码,请参见下文:
但是,我没有通过逻辑分析仪看到传感器的响应。这是我的记录。您将必须单击链接。请注意,第一行是时钟,底部是数据。MSP430 output。从数据表和arduino代码读取传感器的逻辑流程如下:
This is the datasheet for the sensor
有关传感器无响应的任何提示。
CODE
void Read_Diff_pressure(void)
{
int rx_byte;
UCB0CTL1 |= UCTXSTT+ UCTR; // Generating START + I2C transmit (write)
UCB0I2CSA = SDP610Address; // SDP610 7 bit address 0x40
UCB0TXBUF = SDP610Read; // sending the read command 0x78
while(!(UCB0IFG & UCTXIFG)); //wait until reg address got sent
while( UCB0CTL1 & UCTXSTT); //wait till START condition is cleared
UCB0CTL1 |= UCTXSTT; //generate RE-START
UCB0I2CSA = SDP610Address; // SDP610 7 bit address 0x40
UCB0CTL1 &=~ UCTR; //receive mode
while( UCB0CTL1 & UCTXSTT); //wait till START condition is cleared
rx_byte = UCB0RXBUF; //read byte
//while(!(UCB0IFG & UCRXIFG)); //wait while the Byte is being read
UCB0CTL1 |= UCTXNACK; //generate a NACK
UCB0CTL1 |= UCTXSTP; //generate stop condition
while(UCB0CTL1 & UCTXSTP); //wait till stop condition got sent```
Pressure_result = rx_byte;
}
void InitI2C_diff(void)
{
PAOUT |= I2C_SCL_PIN|I2C_SDA_PIN;//P1.2(SDA) - P1.3(SCL) as per silk screen defined in a header
PADIR |= I2C_SCL_PIN|I2C_SDA_PIN;
PASEL0 |= (I2C_SCL_PIN|I2C_SDA_PIN); // configure I2C pins (device specific)
UCB0CTLW0 |= UCSWRST; // put eUSCI_B in reset state
UCB0CTLW0 |= UCMODE_3 | UCSYNC | UCMST; // I2C master mode, SMCL
UCB0CTL1 = UCSSEL_2 + UCSWRST; //use SMCLK + still reset
UCB0BR0 = 10; // default SMCLK 1M/10 = 100KHz
UCB0BR1 = 0; //
UCB0I2CSA = SDP610Address; //The address of the device
UCB0CTLW0 &= ~UCSWRST; // eUSCI_B in operational state
//UCB0BRW = 64; // baudrate = SMCLK / 64
}
int main(void)
{
InitI2C_diff();//Init the i2c
while (1) { // Mainloop
Read_Diff_pressure();
delay(1000);//1 Second delay before re looping
}
}
查看“ I2C测量”图上第5页的链接的数据表,我可以看到以下要求的命令顺序:
设置开始条件
发送I2C设备地址(7位地址+ bit0 = 0进行写入)
从属发送:ACK
发送要读取的I2C寄存器地址(8位)(在您的情况下为0x78?)
从属发送:ACK
重复的开始
发送I2C设备地址(要读取的7位地址+ bit0 = 1)
从属发送:ACK
从属发送:数据
主机发送:NACK(如果您尝试读取的预期数据只有1个字节长,否则主机需要发送ACK)
发送停止
但是,查看您的代码,我可以看到您正在混淆此顺序:
UCB0CTL1 |= UCTXSTT+ UCTR; // Generating START + I2C transmit (write)
UCB0I2CSA = SDP610Address; // SDP610 7 bit address 0x40
UCB0TXBUF = SDP610Read; // sending the read command 0x78
while(!(UCB0IFG & UCTXIFG)); //wait until reg address got sent
用写位写入从机地址后,您应该等待设备的ACK,然后才发送要读取的寄存器地址。