Taos TSL2561 I2C Light-to-Digital Converter - I2C Question

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
Jon Chandler
Registered User
Registered User
Posts: 167
Joined: Mon Mar 10, 2008 8:20 am
Location: Seattle, WA USA
Contact:

Taos TSL2561 I2C Light-to-Digital Converter - I2C Question

Post by Jon Chandler » Tue Sep 22, 2015 1:07 am

Has anyone had any success using this chip with Swordfish? I've used a lot of different I2C chips but this one is somewhat unique. I'm having trouble getting anything from it, and it seems to be related to the command register on page 14 of this data sheet.

In I2C chips I used, you have to set up and read from control registers, but this is the first time I've heard of a command register. To turn the chip on, you must write %00000011 to register $0, but this doesn't seem to accomplish anything. When I read the register back, I get 0 instead of 3.

The address scheme of this chip is unique. They list the possible addresses as $29, $39 or $49, ignoring the LSB which is 0 to read or 1 to write. Adding the zero and converting to decimal, this gives possible addresses of 82, 114 or 146. The address should be 114 according to the way the address pin is configured. Using that address, I get 0 when I read register 0; if I use either of the other choices, I get $FF, so I believe I have the correct address. I just can't get the chip to turn on.

Any ideas?

Thanks,

Jon
Jon

Check out the TAP-28 PIC Application board at http://www.clever4hire.com/throwawaypic/

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Taos TSL2561 I2C Light-to-Digital Converter - I2C Questi

Post by Jerry Messina » Tue Sep 22, 2015 10:09 am

I've never used that chip, but the SMbus format is fairly common. It's confusing with that one since it seems to be a mix of SMbus + regular I2C.

I'm guessing here, but it seems like this might work:

Code: Select all

const TSL2561_ADDR = $39<<1  // default address

const TSL2561_CMD = $80			// select Command register

dim b as byte

// write reg 0 - power on
i2c.start()
i2c.writebyte(TSL2561_ADDR)			// addr + 0 (WR)
i2c.writebyte(TSL2561_CMD + 0)		// CMD + reg 0 addr
i2c.writebyte($03)				    // power on
i2c.stop()

// allow time to power up?
delayms(500)

// read reg 0
i2c.start()                          // set reg 0 addr
i2c.writebyte(TSL2561_ADDR)
i2c.writebyte(TSL2561_CMD + 0)		// CMD + reg 0 addr
i2c.stop()

i2c.start()
i2c.writebyte(TSL2561_ADDR + 1)		// addr + 1 (RD)
b = i2c.readbyte()               // read reg 0
i2c.stop()


Jon Chandler
Registered User
Registered User
Posts: 167
Joined: Mon Mar 10, 2008 8:20 am
Location: Seattle, WA USA
Contact:

Re: Taos TSL2561 I2C Light-to-Digital Converter - I2C Questi

Post by Jon Chandler » Tue Sep 22, 2015 11:21 pm

Thanks for the suggestion Jerry, but no success. It hangs up at some point.

I think the difficulty lies in the SMBus "send byte" vs the I2C "write byte" protocols. I'm wondering if I an just shift out the needed bytes to get the chip turned on, then use the more conventional I2C format.

I'll keep at it. Fortunately, this is a "nice to have" extra on the project I'm working on rather than a show stopper.

Jon
Jon

Check out the TAP-28 PIC Application board at http://www.clever4hire.com/throwawaypic/

Jerry Messina
Swordfish Developer
Posts: 1237
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Taos TSL2561 I2C Light-to-Digital Converter - I2C Questi

Post by Jerry Messina » Wed Sep 23, 2015 10:06 am

I think I misread the datasheet on what format the chip uses. Maybe it's not really all that complicated.

Here's what I'm thinking...
The 2561 is the I2C version, so it only supports the two formats in Figures 16 and 17, BUT it doesn't use the "Byte Count" byte shown in those figures. That sort of makes sense... if you skip those bytes it begins to look like a normal I2C transaction that most chips use.

If that's the case, the Write sequence in the first post should be ok, but try doing this for the read:

Code: Select all

// read reg 0
delayus(2)				// t(BUF) Bus free time between start and stop condition = 1.3us min
i2c.start()
delayus(1)				// t(HDSTA) Hold time after (repeated) start condition = 600ns min
i2c.writebyte(TSL2561_ADDR)			// chip addr (WR)
i2c.writebyte(TSL2561_CMD + 0)      // CMD + reg 0 addr

delayus(1)				// t(SUSTA) Repeated start condition setup time = 600ns min
i2c.restart()                   
delayus(1)				// t(HDSTA) Hold time after (repeated) start condition = 600ns min
i2c.writebyte(TSL2561_ADDR + 1)     // chip addr (RD)
b = i2c.readbyte()               	// read reg 0
i2c.acknowledge(I2C_NOT_ACKNOWLEDGE)
delayus(1)				// t(SUSTO) Stop condition setup time = 600ns min
i2c.stop()
You probably don't need the 'delayus()' calls, but it might be better to leave them in at first... you can always try taking them out later if you get the thing to respond.

Post Reply