How to use I2C with Wc8/Wc32

BTCAD

Active Member
Hi everyone,
                    I would like to know how to use I2C with webcontrol. Code exemple, how to communicate with a sensor using I2C, you know the basic of i2c communication. I search on the forum and to the wc8 manual pdf for answer but i didn't helps enough. I'm sure I2C will help a lot to add sensors, but I need at least to know how to use that.
 
 
 
Thank you all for your support.
 
If we take as exemple BPM180 sensor:
 
 
WebControl 8 firmware from this version on supports I2C device communication
through the top two spare pins with pull up resistors. The first pin is CLK and second
pin is DATA. To communicate with the I2C device, first to send command to the slave
device what to do, then send command to slave what to read back. For example,
BOSCH digital pressure sensor BMP180 has air pressure measurement 16-19bit,
temperature measurement 16 bit. To measure the pressure, first send command to
tell BMP180 start pressure measurement conversion. After specified time for
conversion, then send command to tell BMP180 what PLC program will read back.
To start the pressure conversion, these commands are send to the BMP180:
 
I2CWRITE 1 0 0xEE
I2CWRITE 0 0 0xF4
I2CWRITE 0 1 0xF4
 
The first line tell the BMP180 that WebControl wants to start communication with it.
0xEE is the sensor address on the I2C bus. The second line tell the sensor to start
conversion, 0xF4 is the control register address. The third line tell the sensor which
value to convert, 0xF4 is the pressure OSS = 3, resolution 16 bit.
To read back the conversion result, these command are send to the BMP180:
 
I2CWRITE 1 0 0xEE
I2CWRITE 0 0 0xF6  
I2CWRITE 1 0 0xEF
I2CREAD 0 0 RAM10
I2CREAD 1 1 RAM11 
 
 
 
http://ae-bst.resource.bosch.com/media/products/dokumente/bmp180/BST-BMP180-DS000-09.pdf
page 21
 
 
 
Someone can tell me how it works? 
 
Okay I think I got it...but some questions :
 
 
 
I2CWRITE 1 0 0xEE   <--- here the 0XEE is the module address, by the way why every BPM180 have the same module add? That means that we can't add multiple sensor on i2c bus?
 
And Why do you preffer 0ss = 3 than 0ss = 0 ?
 
0ss3 == 25.5ms 
and
0ss0 == 4.5ms
 
Here the reading part :
 
I2CREAD 0 0 RAM10
I2CREAD 1 1 RAM11 
 
Why do I need 2 ram location? 
 
What is the purpose of the ram10? Send ACK is set to 0, so why we need this location?
 
One more thing, this is the restart part. I would like to know where the  ''0xEF'' come from?

 
I2CWRITE 1 0 0xEE
I2CWRITE 0 0 0xF6  
I2CWRITE 1 0 0xEF
I2CREAD 0 0 RAM10
I2CREAD 1 1 RAM11 
 
BTCAD said:
Here the reading part :
 
I2CREAD 0 0 RAM10
I2CREAD 1 1 RAM11 
 
Why do I need 2 ram location? 
 
What is the purpose of the ram10? Send ACK is set to 0, so why we need this location?
 
One more thing, this is the restart part. I would like to know where the  ''0xEF'' come from?

 
I2CWRITE 1 0 0xEE
I2CWRITE 0 0 0xF6  
I2CWRITE 1 0 0xEF
I2CREAD 0 0 RAM10
I2CREAD 1 1 RAM11 
 
You probably need to sit down and read the BMP180 specs and the I2C protocol specs closely to explain several of these.
Yes, you can only have one BMP180 on an individual I2C bus unless you have some way to disable devices you don't want to respond. This is a "design feature" of the BMP180, and nothing to do with I2C or the WebControl.
OSS sets the oversampling. More oversampling should reduce noise and jitter, but takes more time.
0xEE vs 0xEF, you need to understand the address (7 bits) and read/write register. Refer I2C specifications.
RAM10 and RAM11 are adjacent bytes of RAM1, and an intelligent way of re-assembling the two 8-bit words the WC reads from the I2C bus.
 
BTCAD,
 
The reason in the example using OSS == 3 is that to have 8 times over samples and average the result to be more accurate. Oss value can be 0, 1, 2, and 3, where 0 means sample once, 1 means sample twice, 2, means sample 4 times, and 3 means sample 8 times.  That was specified on datasheet page 18.
 
Did you
 
BTCAD said:
Hi everyone,
                    I would like to know how to use I2C with webcontrol. Code exemple, how to communicate with a sensor using I2C, you know the basic of i2c communication. I search on the forum and to the wc8 manual pdf for answer but i didn't helps enough. I'm sure I2C will help a lot to add sensors, but I need at least to know how to use that.
 
 
 
Thank you all for your support.
 
 
Since the same sensor now sits on my desk to be connected to the WC32, did you succeed?
thanks
 
Okay so 0ss3 is for more accurate reading. Thx

I will order 1 device for the holiday. I will let you know. Do you think guys that is a pain if i purchasse this 1 dual magnetic sensor?



Ebay : 231409915193


Thx
 
It could work, if you can find the datasheet for the I2C GPS receiver commands.  It looks like this sensor has one address also,  that means one board can have only one such axis sensor.  Normally different I2C chip has different I2C default address, so that you can have different I2C chips on the same bus.
 
CAI_Support said:
It could work, if you can find the datasheet for the I2C GPS receiver commands.  It looks like this sensor has one address also,  that means one board can have only one such axis sensor.  Normally different I2C chip has different I2C default address, so that you can have different I2C chips on the same bus.
Okay, 
And this is the same for the BPM180 with only one address : 0XEE ?
 
yeah i found datasheet!
 
It says default address is 0x60, and has four addresses available on page 11.
However, this is not chip's datasheet, it is the datasheet for whole module. To identify the address and know how to program, you need to ask them for the chip datasheet.
 
Back
Top