先试下功能,所以先找了别人代码试用一下,暂未调通,待调通再封装下模块代码。
首先用RASC配置IIC,跟驱动HS3003一样,配置成IIC_Master。
参考了下数据手册,大致初始化接口如下
int32_t DigitalLightISL29035_init(void)
{
uint8_t reg = 0;
reg= DigitalLightISL29035_readRegister( 0x0F);
uint8_t chip_id = (reg >> 3) & 0x7;
if (chip_id != 0x5) {
return -1;
}
DigitalLightISL29035_writeRegister(0x0F, reg & 0x7f);
DigitalLightISL29035_writeRegister( 0x00, 0);
DigitalLightISL29035_writeRegister(0x01, full_scale_lux_range | (integration_time << 2) );
DigitalLightISL29035_writeRegister( 0x00, 0x40);
return 0;
}
写接口如下
void DigitalLightISL29035_writeRegister( int reg_address, uint8_t val)
{
uint8_t ii[2]={0x00,0x00};
ii[0] = reg_address;
ii[1] = val;
R_SCI_I2C_Write(&HS3003_I2C3, ii, 0x02, false);
while ((I2C_MASTER_EVENT_TX_COMPLETE != i2c_event1) && timeout_ms1>0)
{
R_BSP_SoftwareDelay(1U, BSP_DELAY_UNITS_MICROSECONDS);
timeout_ms1--;
}
if (I2C_MASTER_EVENT_ABORTED == i2c_event1)
{
__BKPT(0);
}
i2c_event1 = I2C_MASTER_EVENT_ABORTED;
timeout_ms1 = 100000;
}
读接口如下
uint8_t DigitalLightISL29035_readRegister(uint8_t reg_address)
{
uint8_t value;
R_SCI_I2C_Write(&HS3003_I2C3, ®_address, 0x01, false);
while ((I2C_MASTER_EVENT_TX_COMPLETE != i2c_event1) && timeout_ms1>0)
{
R_BSP_SoftwareDelay(1U, BSP_DELAY_UNITS_MICROSECONDS);
timeout_ms1--;
}
if (I2C_MASTER_EVENT_ABORTED == i2c_event1)
{
__BKPT(0);
}
i2c_event1 = I2C_MASTER_EVENT_ABORTED;
timeout_ms1 = 100000;
R_SCI_I2C_Read(&HS3003_I2C3, &value, 0x01, false);
while ((I2C_MASTER_EVENT_RX_COMPLETE != i2c_event1) && timeout_ms1)
{
R_BSP_SoftwareDelay(1U, BSP_DELAY_UNITS_MILLISECONDS);
timeout_ms1--;
}
if (I2C_MASTER_EVENT_ABORTED == i2c_event1)
{
__BKPT(0);
}
i2c_event1 = I2C_MASTER_EVENT_ABORTED;
timeout_ms1 = 100000;
return value;
}
获取数据代码如下:
uint32_t DigitalLightISL29035_readIRLux(void) {
uint16_t data = 0;
uint8_t l, h;
DigitalLightISL29035_writeRegister( 0x00, 0x40);
if(integration_time==0)
{
R_BSP_SoftwareDelay(105, BSP_DELAY_UNITS_MILLISECONDS);
}
else if(integration_time==1 || integration_time==2)
{
R_BSP_SoftwareDelay(7, BSP_DELAY_UNITS_MILLISECONDS);
}
else if(integration_time==3)
{
R_BSP_SoftwareDelay(1, BSP_DELAY_UNITS_MILLISECONDS);
}
l=DigitalLightISL29035_readRegister(0x02);
h=DigitalLightISL29035_readRegister(0x03);
data=(h << 8) | l;
uint32_t ranges=0;
if(full_scale_lux_range==0)
ranges=1000;
else if(full_scale_lux_range==1)
ranges=4000;
else if(full_scale_lux_range==2)
ranges=16000;
else if(full_scale_lux_range==3)
ranges=64000;
uint32_t adc_count_max=0;
if(integration_time==0)
adc_count_max=65536;
else if(integration_time==1)
adc_count_max=4096;
else if(integration_time==2)
adc_count_max=256;
else if(integration_time==3)
adc_count_max=16;
return ranges * (uint32_t)data /adc_count_max;
}
应用代码(因为地址都是0x44,我这边用的都是同一个口,所以线程名称先用HS3003的顶一下)
void HS3003_Task_entry(void * pvParameters)
{
FSP_PARAMETER_NOT_USED(pvParameters);
DigitalLightISL29035_init();
while(1)
{
ISL29035Data = DigitalLightISL29035_readIRLux();
vTaskDelay(200);
}
}