Page 1 of 1

I2C help

Posted: Thu Dec 08, 2016 1:39 pm
by Jan Lichtenbelt
I started a project to measure UV-B light. I bought a sensor VEML6075 with use I2C to read the data. The datasheet is:
http://www.farnell.com/datasheets/20177 ... 1481200214

My problem is that I never before worked with I2C.

Who can help me to start the development of a flowcode 7 for it?

Be informed:
- The sensor can measure more wavelength, but I need only the UV-B part of the (sun) light.
- I do the soldering of the 4 pins of the sensor (1x2 mm)!

With kind regards

Jan Lichtenbelt

Re: I2C help

Posted: Thu Dec 08, 2016 2:06 pm
by Benj
Hi Jan,

Good luck with the soldering, sounds like you'll need a steady hand.

This article might help to get you up to speed on using I2C.
http://www.flowcode.co.uk/blog/simplifie ... c-and-spi/

Re: I2C help

Posted: Fri Dec 09, 2016 12:55 pm
by Jan Lichtenbelt
Hi Ben,

That helps a lot. The difference for my is that the data needed are 16 bits. I changed the folowcode in a high and low byte, as attachment.

I have a question. The I2C Master has pins on C4 (data) and C3(clock) on the 16F1847 microchip. But this chip does not have these pins. The data sheet show SDA1 on B1 en SCL1 on B4, or SDA2 on B2 and SCL2 on B5. How do I know which pins are used? How can one change that?

With kind regards

Jan Lichtenbelt
UVmeter_V1.fcfx
(11.35 KiB) Downloaded 339 times

Re: I2C help

Posted: Fri Dec 09, 2016 1:19 pm
by QMESAR
Hi

If you change the property for I2C master from Software to Channel 1 or 2 you will see the pins are correct as per data sheet

Re: I2C help

Posted: Fri Dec 09, 2016 1:21 pm
by Benj
Hi Jan,

Hmm that's odd the definition file looks correct.

Code: Select all

    <i2c master='0' >
        <sda port='1' pin='1' />
        <scl port='1' pin='4' />
    </i2c>
    <i2c master='0' >
        <sda port='1' pin='2' />
        <scl port='1' pin='5' />
    </i2c>
Here is the latest FCD just in case you have a different version.
16F1847.fcdx
(23.9 KiB) Downloaded 314 times

Re: I2C help

Posted: Mon Jan 16, 2017 7:55 pm
by Jan Lichtenbelt
It is still very hard for me to understand I2C well. Can someone help me.

Please find my flowcode the measure the UV_B light intensity of an UV sensor VEML6075. It does not work correctly, which can be due to a Flowcode error or hardware. I found a C-code programm (attached) which I use as example for the Flowcode. The read and write I2C procedure for reading/writing a word is given in the picture.

With kind regards

Jan Lichtenbelt
PS. Pay attention: The 16LF1847 microchip has been used in this Flowcode
UVmeter_V3.fcfx
(18.62 KiB) Downloaded 314 times
VEML6075.c
(2.99 KiB) Downloaded 309 times
VEML6075_Command_Protocol_Format.jpg
VEML6075_Command_Protocol_Format.jpg (53.03 KiB) Viewed 8359 times

Re: I2C help

Posted: Mon Jan 16, 2017 8:33 pm
by JohnCrow
Hi Jan

I too think I2C can be a difficult concept. Sometimes I can get something to work fairly easily and other times I can really struggle with the device.

I bought a book on the subject from Elektor

Mastering The I2C BUS by Vincent Himpe, it does cover everything from the basics to advanced topics.

Like most of the books published by Elektor, its quite a good reference source.

Re: I2C help

Posted: Tue Jan 17, 2017 9:39 am
by LeighM
Hi Jan,
Your flowchart looks neat, just one typo I spotted.. in Receive_Data the "Read Databyte High" has a TransmitByte that should be ReceiveByte
Hope that helps
Leigh

Re: I2C help

Posted: Wed Jan 18, 2017 1:25 pm
by Jay Dee
Hi Jan,
Foe me the bit I have to remember in i2C are,
Pull up resistors on Clock and Data Line.

Remembering its a 7 Bit Address + the Read or Write Bit.

With my current project, the external ADC Chips i2c has....
The read/write bit is 1 for Read, 0 for Write.

So if the hardware 7 bit address is ( 0x4C ) in binary 0b1001100
the actual byte sent is, the address bit shifted left by 1 + R/W bit.
thus
(0x98) 0b10011000 for a Write
and
(0x99) 0b10011001 for a Read.

+Live scope decoding is a real luxury!! J.

Re: I2C help

Posted: Fri Jan 20, 2017 2:03 pm
by Jan Lichtenbelt
Hi LeighM and Steve

It works! That means I can read the device ID. But this UV sensor still gives intensity of zero, probably due to the less sunshine these days.
But the soldering of the 1x2mm with 4 pins is possible even by a hobbyist like me!

With kind regards

Jan Lichtenbelt