我希望在非中断模式下使用 driverlib 函数来读取产品标识和序列号时能有所帮助
传感器的热性能。
我已附上所需的数据格式。

谢谢
David Nyarko 
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.
我希望在非中断模式下使用 driverlib 函数来读取产品标识和序列号时能有所帮助
传感器的热性能。
我已附上所需的数据格式。

谢谢
David Nyarko 
尊敬的 David:
明白了、看起来很简单。 对于处理读取长数据包的无中断示例、您的最佳起点是位于[Install Path]\TivaWare_C_Series-2.2.0.295\examples\boards\ek-tm4c1294xl-bootstxl-senshub\Humid_sht21_simple 的示例
请注意、这是 TivaWare 2.2.0.295的新示例、因为我们在之前的版本中缺少与您类似的使用案例的良好示例。
其中包含一个写入命令、您可以使用该命令将前两条命令发送到传感器、然后是一个读取命令、只需稍作修改即可处理您的用例。 您需要为 I2C_MASTER_CMD_BURST_RECEIVE _RECEIVE STEP 创建一个循环以使其持续读取、直到您在中断循环之前按字节17并使用 I2C_MASTER_CMD_BURST_RECEIT_RECEACT_FINISH 步骤完成接收 CRC6。
此致、
Ralph Jacobi
我很清楚为什么你会问这个特定的实现、我很惊讶每一个都是基于中断的。
我可以组合一个在星期一实际测试的无中断版本、但为了代替这一版本、这些函数也应该适用于您的 MSP432E4、因为 TivaWare 和 MSP432E4 SDK 之间使用的 driverlib 实际上是相同的:
//*****************************************************************************
//
// This function sends the specified command to the I2C slave device.
//
//*****************************************************************************
void
I2CWriteCommand(uint32_t ui32Command)
{
//
// Set up the slave address with write transaction.
//
MAP_I2CMasterSlaveAddrSet(I2C7_BASE, SHT21_I2C_ADDRESS, false);
//
// Store the command data in I2C data register.
//
MAP_I2CMasterDataPut(I2C7_BASE, ui32Command);
//
// Start the I2C transaction.
//
MAP_I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_SINGLE_SEND);
//
// Wait until the I2C transaction is complete.
//
while(MAP_I2CMasterBusy(I2C7_BASE))
{
}
}
//*****************************************************************************
//
// This function will read three 8-bit data from the I2C slave. The first
// two 8-bit data forms the humidity data while the last 8-bit data is the
// checksum. This function illustrates three different I2C burst mode
// commands to read the I2C slave device.
//
//*****************************************************************************
void
I2CReadCommand(uint32_t * pui32DataRx)
{
//
// Modify the data direction to true, so that seeing the address will
// indicate that the I2C Master is initiating a read from the slave.
//
MAP_I2CMasterSlaveAddrSet(I2C7_BASE, SHT21_I2C_ADDRESS, true);
//
// Setup for first read. Use I2C_MASTER_CMD_BURST_RECEIVE_START
// to start a burst mode read. The I2C master continues to own
// the bus at the end of this transaction.
//
MAP_I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
//
// Wait until master module is done transferring.
// The I2C module has a delay in setting the Busy flag in the register so
// there needs to be a delay before checking the Busy bit. The below loops
// wait until the Busy flag is set, and then wait until it is cleared to
// indicate that the transaction is complete. This can take up to 633 CPU
// cycles @ 100 kbit I2C Baud Rate and 120 MHz System Clock. Therefore, a
// while loop is used instead of SysCtlDelay.
//
while(!MAP_I2CMasterBusy(I2C7_BASE))
{
}
while(MAP_I2CMasterBusy(I2C7_BASE))
{
}
//
// Read the first byte data from the slave.
//
pui32DataRx[0] = MAP_I2CMasterDataGet(I2C7_BASE);
//
// Setup for the second read. Use I2C_MASTER_CMD_BURST_RECEIVE_CONT
// to continue the burst mode read. The I2C master continues to own
// the bus at the end of this transaction.
//
MAP_I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
//
// Wait until master module is done transferring.
//
while(!MAP_I2CMasterBusy(I2C7_BASE))
{
}
while(MAP_I2CMasterBusy(I2C7_BASE))
{
}
//
// Read the second byte data from the slave.
//
pui32DataRx[1] = MAP_I2CMasterDataGet(I2C7_BASE);
//
// Setup for the third read. Use I2C_MASTER_CMD_BURST_RECEIVE_FINISH
// to terminate the I2C transaction. At the end of this transaction,
// the STOP bit will be issued and the I2C bus is returned to the
// Idle state.
//
MAP_I2CMasterControl(I2C7_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
//
// Wait until master module is done transferring.
//
while(!MAP_I2CMasterBusy(I2C7_BASE))
{
}
while(MAP_I2CMasterBusy(I2C7_BASE))
{
}
//
// Note the third 8-bit data is the checksum byte. It will be
// left to the users as an exercise if they want to verify if the
// checksum is correct.
pui32DataRx[2] = MAP_I2CMasterDataGet(I2C7_BASE);
}
如果这能让您启动并运行、那么在我星期一返回之前、请告诉我
此致、
Ralph Jacobi
尊敬的 David:
因此、如果没有正确反应的传感器、我无法完全测试这一点、但我认为这是应该起作用的:
//*****************************************************************************
//
// This function will read three 8-bit data from the I2C slave. The first
// two 8-bit data forms the humidity data while the last 8-bit data is the
// checksum. This function illustrates three different I2C burst mode
// commands to read the I2C slave device.
//
//*****************************************************************************
void
I2CReadSensor(uint32_t * ui32Cmd1, uint32_t * ui32Cmd2, uint32_t * pui32DataRx)
{
uint8_t ui8DataIndex = 0;
/* Put the Slave Address on the bus for Write */
MAP_I2CMasterSlaveAddrSet(I2C1_BASE, SLAVE_ADDRESS, false);
/* Write the first byte of the command to the bus */
MAP_I2CMasterDataPut(I2C1_BASE, ui32Cmd1[0]);
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
/* Wait until the I2C transaction is complete. */
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Send the second byte of the command to the bus */
MAP_I2CMasterDataPut(I2C1_BASE, ui32Cmd1[1]);
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
/* Wait until the I2C transaction is complete. */
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Put the Slave Address on the bus for Write */
MAP_I2CMasterSlaveAddrSet(I2C1_BASE, SLAVE_ADDRESS, false);
/* Write the first byte of the command to the bus */
MAP_I2CMasterDataPut(I2C1_BASE, ui32Cmd2[0]);
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
/* Wait until the I2C transaction is complete. */
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Send the second byte of the command to the bus */
MAP_I2CMasterDataPut(I2C1_BASE, ui32Cmd2[1]);
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
/* Wait until the I2C transaction is complete. */
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Modify the data direction to true, so that seeing the address will
* indicate that the I2C Master is initiating a read from the slave. */
MAP_I2CMasterSlaveAddrSet(I2C1_BASE, SLAVE_ADDRESS, true);
/* Setup for first read. Use I2C_MASTER_CMD_BURST_RECEIVE_START
* to start a burst mode read. The I2C master continues to own
* the bus at the end of this transaction. */
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
/* Wait until master module is done transferring.
* The I2C module has a delay in setting the Busy flag in the register so
* there needs to be a delay before checking the Busy bit. The below loops
* wait until the Busy flag is set, and then wait until it is cleared to
* indicate that the transaction is complete. This can take up to 633 CPU
* cycles @ 100 kbit I2C Baud Rate and 120 MHz System Clock. Therefore, a
* while loop is used instead of SysCtlDelay. */
while(!MAP_I2CMasterBusy(I2C1_BASE))
{
}
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Read the first byte data from the slave. */
pui32DataRx[ui8DataIndex++] = MAP_I2CMasterDataGet(I2C1_BASE);
while (ui8DataIndex < 17)
{
/* Setup for the next read. Use I2C_MASTER_CMD_BURST_RECEIVE_CONT
* to continue the burst mode read. The I2C master continues to own
* the bus at the end of this transaction. */
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
/* Wait until master module is done transferring. */
while(!MAP_I2CMasterBusy(I2C1_BASE))
{
}
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Read the next byte data from the slave. */
pui32DataRx[ui8DataIndex++] = MAP_I2CMasterDataGet(I2C1_BASE);
}
/* Setup for the third read. Use I2C_MASTER_CMD_BURST_RECEIVE_FINISH
* to terminate the I2C transaction. At the end of this transaction,
* the STOP bit will be issued and the I2C bus is returned to the
* Idle state. */
MAP_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
/* Wait until master module is done transferring. */
while(!MAP_I2CMasterBusy(I2C1_BASE))
{
}
while(MAP_I2CMasterBusy(I2C1_BASE))
{
}
/* Note the third 8-bit data is the checksum byte. It will be
* left to the users as an exercise if they want to verify if the
* checksum is correct. */
pui32DataRx[ui8DataIndex++] = MAP_I2CMasterDataGet(I2C1_BASE);
}
int main(void)
{
uint32_t systemClock;
/* Variables for I2C data and state machine */
uint32_t ui32Cmd1[2] = {0xAA, 0xBB};
uint32_t ui32Cmd2[2] = {0xCC, 0xDD};
uint32_t ui32SensorData[18] = {0x00};
/* Configure the system clock for 120 MHz */
systemClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
120000000);
/* Enable clocks to GPIO Port G and configure pins as I2C */
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
while(!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOG)))
{
}
MAP_GPIOPinConfigure(GPIO_PG0_I2C1SCL);
MAP_GPIOPinConfigure(GPIO_PG1_I2C1SDA);
MAP_GPIOPinTypeI2C(GPIO_PORTG_BASE, GPIO_PIN_1);
MAP_GPIOPinTypeI2CSCL(GPIO_PORTG_BASE, GPIO_PIN_0);
/* Since there are no board pull up's we shall enable the weak internal
* pull up */
GPIOG->PUR |= (GPIO_PIN_1 | GPIO_PIN_0);
/* Enable the clock to I2C-1 module and configure the I2C Master */
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
while(!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_I2C1)))
{
}
/* Configure the I2C Master in standard mode and enable interrupt for Data
* completion, NAK and Stop condition on the bus */
MAP_I2CMasterInitExpClk(I2C1_BASE, systemClock, false);
I2CReadSensor(&ui32Cmd1[0], &ui32Cmd2[0], &ui32SensorData[0]);
while(1)
{
}
}
(首次发布后5分钟进行了两次小改动)
此致、
Ralph Jacobi