I am using MCP3021 for my ambient light sensor. I am getting bytes successfully on reading but unable to process them properly. I am using MPLABX as my IDE.
My code is as follows,
UINT32 res, val, upper, lower;
UINT8 i2cbyte[10]; // I2C values get stored in this one...
// example values : i2cbyte[0]=0x0e, i2cbyte[1]=0x32
upper = i2cbyte[0];
lower = i2cbyte[1];
val = ( upper << 6) + (lower >> 2);
//after this value is: upper = 0x00000380, lower = 0x01000032 & val is same as lower
No idea why variable lower has a 01 in it.Sometimes value is 0x00cccc32.
res = upper + lower; // res = 0x0000320E
res = (3.3/1024) * val;
Can someone help me with this?