TSL2562, TSL2563
LOW-VOLTAGE
LIGHT-TO-DIGITAL CONVERTER
TAOS066J − MAY 2007
APPLICATION INFORMATION: SOFTWARE
The following example pseudo code illustrates the configuration of an SMB Alert style interrupt when the light
intensity changes 20% from the current value, and persists for 3 conversion cycles:
// Read current light level
Address = 0x39
Command = 0xAC
//Slave addr also 0x29 or 0x49
//Set Command bit and Word bit
ReadWord (Address, Command, DataLow, DataHigh)
Channel0 = (256 * DataHigh) + DataLow
//Calculate upper and lower thresholds
T_Upper = Channel0 + (0.2 * Channel0)
T_Lower = Channel0 – (0.2 * Channel0)
//Write the lower threshold register
Command = 0xA2
//Addr lower threshold reg, set Word Bit
WriteWord (Address, Command, T_Lower.LoByte, T_Lower.HiByte)
//Write the upper threshold register
Command = 0xA4
//Addr upper threshold reg, set Word bit
WriteWord (Address, Command, T_Upper.LoByte, T_Upper.HiByte)
//Enable interrupt
Command = 0x86
Data = 0x23
//Address interrupt register
//SMBAlert style, PERSIST = 3
WriteByte(Address, Command, Data)
In order to generate an interrupt on demand during system test or debug, a test mode (INTR = 11) can be used.
The following example illustrates how to generate an interrupt on demand:
// Generate an interrupt
Address = 0x39
Command = 0x86
Data = 0x30
//Slave addr also 0x29 or 0x49
//Address Interrupt register
//Test interrupt
WriteByte(Address, Command, Data)
//Interrupt line should now be low
Copyright E 2007, TAOS Inc.
The LUMENOLOGY r Company
r
r
www.taosinc.com
21