Reply
Posts: 2
Registered: ‎08-11-2017

SI1133 - Does not measure with nrf52832 µC

HI,

 

I'm trying to use the SI1133. My sensor is running because i can read the device ID, but IRQ_STATUS never change, and i can't read uv value.

 

here my main program:

int main(void)
{
	uint8_t buffer[2];
	uint16_t uv;
	
	ret_code_t err_code;
	
	bsp_board_leds_init();
	bsp_board_led_on(2);

	twi_config(&m_twi);
	
	err_code = SI1133_configuration(&m_twi);
//	err_code = SI1133_START(&m_twi);
	
//	
	while(1)
	{
		buffer[0] = 0x00;
		buffer[1] = 0x00;
		
				
		err_code = SI1133_readUV_value(&m_twi,0x01, buffer);
		
		//uv = (buffer[0] << 8) + buffer[1];
		
		if(buffer[0]  > 0x00 || buffer[1] > 0x00)
		{
			bsp_board_led_on(0);
			nrf_delay_ms(500);
			bsp_board_led_off(0);
		}
		
		if(buffer[1] == 0x00)
		{
			bsp_board_led_on(1);
			nrf_delay_ms(500);
			bsp_board_led_off(1);
		}

		nrf_delay_ms(500);
	}

}


Here my code for the configuration:

ret_code_t SI1133_configuration(nrf_drv_twi_t const *m_twi_master)
{
	begin:
	ret_code_t err_code;
	
	/*Low energy for I2C port*/
	bsp_board_led_off(3);
	
	uint8_t rx_buffer = 0;

	
/****************************Reset SI1133********************************/

//	err_code = SI1133_reset(m_twi_master);
	
/****************************Check device ID********************************/
		
	err_code = SI1133_Register_Read(m_twi_master,SI1133_REG_PART_ID,&rx_buffer);
	if(rx_buffer != SI1133_DEVICE_ID) goto begin;
	
	
/****************************Wait until sleep********************************/
	
	err_code = SI1133_wait_untilSleep(m_twi_master);
	
/****************************param configuration********************************/

	err_code = SI1133_writeParam(m_twi_master,SI1133_PARAM_CH_LIST,0x01);
	err_code = SI1133_writeParam(m_twi_master,SI1133_PARAM_ADCCONFIG0,0x18); //0x18 : DECIM_RATE = 0 ; ADCMUX = UV
	err_code = SI1133_writeParam(m_twi_master,SI1133_PARAM_ADCSENS0,0x71); //0x01 : SW_GAIN = 0 ; HW_GAIN = 1
	err_code = SI1133_writeParam(m_twi_master,SI1133_PARAM_ADCPOST0,0x38); //0x38 : 24BIT_OUT = 0 (16BITS MODE) ; POSTSHIFT = 7 ; THRESH_EN = 0
	err_code = SI1133_writeParam(m_twi_master,SI1133_PARAM_MEASCONFIG0,0x40); //0x40 : COUNTER_INDEX = 1

	err_code = SI1133_writeParam(m_twi_master,SI1133_PARAM_MEASRATE_H,0x00); //0x00 : 
	err_code = SI1133_writeParam(m_twi_master,SI1133_PARAM_MEASRATE_L,0x7D); //0x7D : MEASEATE_H + MEASRATE_L = 50Hz
	
	err_code = SI1133_writeParam(m_twi_master,SI1133_PARAM_MEASCOUNT0,0x01); //0x01 : 

	err_code = SI1133_Register_Write(m_twi_master,SI1133_REG_IRQ_ENABLE,0x01);
	
	return err_code;
}

here my code to read the UV value:

ret_code_t SI1133_readUV_value(nrf_drv_twi_t const *m_twi_master,uint8_t channel, uint8_t *value)
{
	ret_code_t ret; 
	uint8_t buf1,buf2, response;
	uint8_t reg_most_sb_address, reg_lsb_address;
	
	switch(channel)
	{
		case 1:
			reg_most_sb_address = 0x13;
			reg_lsb_address = 0x14;
			break;
		case 2:
			reg_most_sb_address = 0x15;
			reg_lsb_address = 0x16;
			break;
		case 3:
			reg_most_sb_address = 0x17;
			reg_lsb_address = 0x18;
			break;
		case 4:
			reg_most_sb_address = 0x19;
			reg_lsb_address = 0x1A;
			break;
		case 5:
			reg_most_sb_address = 0x1B;
			reg_lsb_address = 0x1C;
			break;
		default:
			reg_most_sb_address = 0x13;
			reg_lsb_address = 0x14;
			break;
	}
	
	ret = SI1133_FORCE(m_twi_master);
	nrf_delay_ms(200);

	ret = SI1133_Register_Read(m_twi_master,SI1133_REG_IRQ_STATUS,&response);
	if(response != 0x01)
	{
		nrf_delay_ms(5);
		ret = SI1133_Register_Read(m_twi_master,SI1133_REG_IRQ_STATUS,&response);

	}
	
	
	ret = SI1133_Register_Read(m_twi_master,reg_most_sb_address, &buf1);
	ret = SI1133_Register_Read(m_twi_master,reg_lsb_address, &buf2);
	
	value[0] = buf1;
	value[1] = buf2;
	
	return ret;
}

 

write param function:

ret_code_t SI1133_writeParam(nrf_drv_twi_t const *m_twi_master, uint8_t reg_number,uint8_t value)
{
	ret_code_t ret;
	uint8_t rxBuffer;
	uint8_t reg_param;

	
	ret = SI1133_Register_Read(m_twi_master, SI1133_REG_RESPONSE0, &rxBuffer);
	ret = SI1133_Register_Write(m_twi_master,SI1133_REG_HOSTIN0,value);
	reg_param = 0x80 | reg_number;
	ret = SI1133_Register_Write(m_twi_master,SI1133_REG_COMMAND,reg_param);
	ret = SI1133_Register_Read(m_twi_master,SI1133_REG_RESPONSE0, &rxBuffer);

	
	return ret;
}

write register function :

ret_code_t SI1133_Register_Write(nrf_drv_twi_t const *m_twi_master, uint8_t reg_number, uint8_t value)
{
	ret_code_t ret;
	
	uint8_t data[2];
	
	data[0] = reg_number;
	data[1] = value;
	
	do
	{
		ret = nrf_drv_twi_tx(m_twi_master,SI1133_I2C_DEVICE_BUS_ADDRESS, data, sizeof(data), true);
		nrf_delay_ms(10);
	}
	while(ret != SI1133_OK);

	return ret;
}

and to read the register value i'm using this function :

ret_code_t SI1133_Register_Read(nrf_drv_twi_t const *m_twi_master, uint8_t reg_number, uint8_t *data)
{
	ret_code_t ret;

	uint8_t cmd = reg_number;

	ret = nrf_drv_twi_tx(m_twi_master,SI1133_I2C_DEVICE_BUS_ADDRESS,&cmd,sizeof(cmd),true);

	if(ret == SI1133_OK)
	{
		ret = nrf_drv_twi_rx(m_twi_master,SI1133_I2C_DEVICE_BUS_ADDRESS,data,sizeof(data));
	}
	
	nrf_delay_ms(10);
	
	return ret;
}

Do you have any idea of my mistake?

 

Thanks for support.

Yggdral

Posts: 97
Registered: ‎04-09-2015

Re: SI1133 - Does not measure with nrf52832 µC

Replied in the technical support portal. Please follow up there.

 

Regards,

Tony

Posts: 2
Registered: ‎08-11-2017

Re: SI1133 - Does not measure with nrf52832 µC

Thanks for your answer,

 

I just try your solution before, it's not working... It seems to work when i try to use the large white sensor (ADCCONFIG0 = 0x0D)  but not for UV sensor (ADCCONFIG0 = 0x18).

 

 

Thanks for support.

Yggdral

Posts: 97
Registered: ‎04-09-2015

Re: SI1133 - Does not measure with nrf52832 µC

Instead of polling the IRQ_STATUS register, can you probe the INT pin and see if you ever get an interrupt from the UV measurement?

 

Changing the photodiode configuration shouldn't affect the interrupt engine. 

 

Regards,

Tony