Embedded C bit math syntax usage question

Dear All,

Seeking some help to interpret couple of syntax expressions used in program and failing. The

*a = Wire.read(); is used to capture data from sensor, via I2C-bus. What i cant understand what does the * multiplication sigh in front mean?

Also what is unclear for me, where does &aa, and &bb come from in expression getCN75data(&aa,&bb); and why does the bitwise ANDing done here?

Any help highly appreciated here.

:)))

The hole code is site here:

void setup()
{
Wire.begin(); // wake up I2C bus
Serial.begin(9600);
}

void getCN75data(byte *a, byte *b)
{
// move the register pointer back to the first register
Wire.beginTransmission(cn75address); // "Hey, CN75 @ 0x48! Message for you"
Wire.write(0); // "move your register pointer back to 00h"
Wire.endTransmission(); // "Thanks, goodbye..."
// now get the data from the CN75
Wire.requestFrom(cn75address, 2); // "Hey, CN75 @ 0x48 - please send me the contents of your first two registers"
*a = Wire.read(); // first received byte stored here
*b = Wire.read(); // second received byte stored here
}

void showCN75data()
{
byte aa,bb;
float temperature=0;
getCN75data(&aa,&bb);
if (aa>127) // check for below zero degrees
{
temperature=((aa-128)*-1);
if (bb==128) // check for 0.5 fraction
{
temperature-=0.5;
}
}
else // it must be above zero degrees
{
temperature=aa;
if (bb==128) // check for 0.5 fraction
{
temperature+=0.5;
}
}
Serial.print("Temperature = ");
Serial.print(temperature,1);
Serial.println(" degrees C");
delay(1000);
}

void loop()
{
showCN75data();
}

In a declaration, '' means "pointer to". It stores the address of a variable.
In an expression, '
' means "that which is pointed to by". It's also know as 'dereferencing' the pointer.

The '&' when passing 'aa' and 'bb' to the function means "address of". It makes a pointer to the value to pass to the function.

Integer variables, like aa and bb, are normally "passed by value" so a function you pass them to gets a COPY of the variable's value. The function can't change the variable since all it has is a copy of the value. If you want the function to be able to change the integer variables you pass to it, you can pass a pointer to the variable. The function can then use the pointer to write into the variable.

*a = Wire.read()can also be writtena[0] = Wire.read()

And.... Arguably, it would be much better "style" to use a reference, rather than a pointer....

Regards,
Ray L.

So as I understand this means a[0]=Wire.Read(); we have read the Wire transmission data and store it in string named a. it this manner shoudnt the value in brakets be empty, i mean a=Wire.Read(); My program is as follows:

Although after running this code on Arduino Uno, in Serial monitor I see just this :frowning:

______________________________Serial. data on screen

Connecting to I2C Data-Bus
20
0255
Connecting to I2C Data-Bus
20
0255
Connecting to I2C Data-Bus

////////////////////////////////////////////////////////////////Program code

#include <Wire.h> // inter-integrated circuit library and protocols injection

byte X1_data_bit; // variables to store the data incoming from the device on the I2C data bus
byte X2_data_bit; // depending on the device may vary the amount of the data sent to master
byte X3_data_bit;
int tau=1000;

void setup()
{
Wire.begin(); // inter-integrated circuit data-bus lock-in…
Serial.begin(9600);
}

void loop()
{
LM_75_SENS();

delay(tau);
}

void LM_75_SENS()
{
Serial.println(“Connecting to I2C Data-Bus”);

Wire.beginTransmission(0x48); // hex value is the device address from datasheet being connected to in hex or binary

Wire.write(0); // sending 0 byte to the device with above mentioned address

Wire.requestFrom(0x48, 3); // requesting 3 bytes of data form the slave device which is stored in suitable variables X1…X2…X3…

Serial.println(X1_data_bit=Wire.read());

//Serial.println(X2_data_bit=Wire.read()); // capturing the transmission data from the slave with the three variables X1…X2…X3…

//Serial.println(X3_data_bit=Wire.read());

Wire.endTransmission(0x48);
}

shoudnt the value in brakets be empty, i mean a=Wire.Read();

Where have you seen code written like that?

Please use code tags when posting code

I havent seen it, I am just trying to learn something from what your wrote. Could you please explain more detailed the expression

a[0]=Wire.read(); what zero in brackets actually stands for?

It's just the first element of the array a.

I see, thats what i actually thougth. In that case the Wire.read(); does not fetch more bits than one? where its gonna save the other bits then?

It returns a byte, not a bit.

how to asseble that byte into something readable=?, lets say value, or temperature. I cant find any conversion formulas in the datasheet of the temeprature sensor I use here.

Its LM-75A, national semicondctor

You don't need to reinvent the wheel, there's a library at Github.

i am not reinventing the wheel, rather than trying to undestand some fundamenthal things. If i wanted to make a copy-paste, wouidnt have spent hours here, trying to get some useful replies.

Why don't you tell us what your problem is?

If you want to understand fundamentals, start with fundamentals, not three-quarters the way to complex.

I need a hint how to assemble the bits coming from the transmisson into something readable, lets say a value. I have 8 bits of data stream and want to convert them into float or integer value.