2019-03-19 02:54 AM
Hi
I purchased the TSL2591 product and used it on the STM32 board.
I am reading the datasheet and creating the code.
I initialized the first writable registers to 0x00.
I then looked at the datasheet and gave the control register a value of 0xB0.
The configuration uses 0xD3 in the enable register, 0x00 in the control register, and 0x09 in the persist register.
I read the PID and ID registers and got a 4 digit number.
After that, I read the thresholds 0x14 and 0x15 (the value of 5 came out).
The lower and upper bytes of CH0 and CH1 have been read (CH0 is 21, CH1 is 18).
The two values did not change with illumination.
I have an interrupt in the datasheet and I do not know how to handle it.
Then I got a question, Is the INT pin in the product a pin for an external interrupt?
I think I do not have much use for the INT in the datasheet.
Could you help me?
What is ALS? ALS interrupt is also required.
In the status register, the sixth bit says that the device should be specified when it encounters an interrupt condition that does not persist. Is it written as 1?
Also, is it correct to write the lsb of the status register to 1 if the AEN bit is used?
The fundamental problem is how to use interrupts generated by the TSL2591 to measure the illuminance.
I'll be waiting for a reply.
The board I am using now is STM32F407VGT.
I am using the STM32 HAL library.
I looked in github, but there was only Arduino.
So I wrote here to get technical support.
Additional questions
How can I fix the thresholds?
2019-03-26 10:08 AM
Hi, I suggest you to forward your question to the STM32 Q&A section
https://community.st.com/s/topic/0TO0X000000BSqSWAW/stm32-mcus
2019-05-14 01:28 AM
I just got the TSL2591 board and tried to read with STM32L4 but it is not working. So can you please help me. Provide all configuration which you have done.
2019-05-14 08:21 PM
@SKim.14 please help me to read this sensor. I am unable to read the device id(0x12 register), it always giving me the zero value.
2019-05-14 10:12 PM
Here, my setting to read the device ID. Can someone help me on this.
int main(void)
{
uint8_t user_rd;
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
MX_I2C1_Init();
UART_Print("*************** STM32L462CE_I2C_TSL2591 ****************\r\n");
status = HAL_I2C_IsDeviceReady(&hi2c1, TSL2591<<1, 3, 1000);
if(status != HAL_OK)
{
UART_Print("Err ...%d %d\r\n",__LINE__,status);
}
else
{
UART_Print("@@@@ TSL2591 Device is Ready @@@@\r\n");
}
TSL2591_WR_USER_Reg(TSL2591__CONFIG,0xB0);
TSL2591_WR_USER_Reg(TSL2591__ENABLE,0xD3);
TSL2591_WR_USER_Reg(TSL2591__CONFIG,0x00);
TSL2591_WR_USER_Reg(TSL2591__PERSIST,0x09);
while (1)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_15);
user_rd = TSL2591_DeviceID();
UART_Print("TSL2591 DeviceID is %x\r\n",user_rd);
HAL_Delay(1000);
}
}
void TSL2591_WR_USER_Reg(uint8_t addr, uint8_t user_data)
{
uint8_t buf[2] = {addr , user_data};
HAL_Delay(20);
status = HAL_I2C_Master_Transmit(&hi2c1, TSL2591<<1, buf, 2, 100);
if(status != HAL_OK)
{
UART_Print("Err ...%d\r\n",__LINE__);
}
}
uint8_t TSL2591_DeviceID(void)
{
uint8_t rd_data;
status = HAL_I2C_Master_Transmit(&hi2c1, TSL2591<<1, &EN_REG, 1, 100);
if(status != HAL_OK)
{
UART_Print("Err ...%d\r\n",__LINE__);
}
HAL_Delay(20);
status = HAL_I2C_Master_Receive(&hi2c1, TSL2591<<1, &rd_data, 1, 100);
if(status != HAL_OK)
{
UART_Print("Err ...%d\r\n",__LINE__);
}
return rd_data;
}
static void MX_I2C1_Init(void)
{
hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x00000E14;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
/**Configure Analogue filter*/
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
{
Error_Handler();
}
/**Configure Digital filter*/
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
{
Error_Handler();
}
}