1. Sending mode: Send slave address: 0x23, send instruction 0x10; end;
Wait 180ms for data collection;
2. Receiving mode: Send slave address: 0x23, wait for high byte data from slave, send response signal after receiving data, wait for low byte data from slave, send non-response signal after receiving data, and end;
It should be noted that in TMS570, only the slave address needs to be filled in i2cSetSlaveAdd(). The first byte sent after i2cSetStart(i2cREG1) is the slave address, which is filled with '0' in transmit mode and '1' in receive mode.
I2C Global:
Need to pay attention to pin multiplexing;
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "i2c.h"
#include "rti.h"
#include "het.h"
#include "pinmux.h"
/* USER CODE END */
/* USER CODE BEGIN (2) */
uint8 is_stop = 0;
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
i2cInit();
rtiInit();
hetInit();
muxInit();
_enable_IRQ();
uint8 high_Byte =0,low_Byte = 0;
i2cSetSlaveAdd(i2cREG1, 0x23 );
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStop(i2cREG1);
i2cSetStart(i2cREG1);
i2cSendByte(i2cREG1, 0x10);
i2cSetStop(i2cREG1);
while(i2cIsBusBusy(i2cREG1) == true);
while(i2cIsStopDetected(i2cREG1) == 0);
/* Clear the Stop condition */
i2cClearSCD(i2cREG1);
// pinmuxGetConfigValue(REVISION_REG,CurrentValue);
rtiREG1->CMP[0U].COMPx = 1800000U;
rtiREG1->CMP[0U].UDCPx = 1800000U;
rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
rtiStartCounter(rtiCOUNTER_BLOCK0);
while(is_stop);
rtiStopCounter(rtiCOUNTER_BLOCK0);
i2cSetSlaveAdd(i2cREG1, 0x23);
i2cSetDirection(i2cREG1, I2C_RECEIVER);
i2cSetMode(i2cREG1, I2C_MASTER);
i2cSetStart(i2cREG1);
high_Byte = i2cReceiveByte(i2cREG1);
i2cREG1->STR |=1<<13;
low_Byte = i2cReceiveByte(i2cREG1);
i2cSetStop(i2cREG1);
asm(" nop");
asm(" nop");
asm(" nop");
while(1);
/* USER CODE END */
return 0;
}
/* USER CODE BEGIN (4) */
void rtiNotification(uint32 notification)
{
is_stop = 1;
}
/* USER CODE END */
Here I use RTI timing method for delay;
|