TMS570LS1224_GY30光照度传感器驱动
[复制链接]
1.发送模式:发送从机地址:0x23,发送指令 0x10;结束;
等待180ms,等待数据采集;
2.接受模式:发送从机地址:0x23,等待从机高字节数据,接受到数据后发送应答信号,等待从机低字节数据,接受到数据后发送非应答信号,结束;
应注意在TMS570中 ,只需要在i2cSetSlaveAdd( )中填入从机地址,在i2cSetStart(i2cREG1)后第一个发送字节就是从机地址,发送模式下补‘0’,接收模式下补‘1’。
I2C Global:
需要注意引脚复用;
#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 */
在这里延时我采用RTI定时方式;
|