I2C Read All Bytes - to bits | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 4 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
I2C Read All Bytes - to bits
November 24, 2015
7:03 pm
Avatar
Kbet
Member
Forum Posts: 4
Member Since:
March 19, 2015
sp_UserOfflineSmall Offline

MCP9808_pg2.jpgImage EnlargerMCP9808_TaReg-1.jpgImage EnlargerHi,

I'm attempting to read data from a MCP9808 via I2C.  I'm uncertain about the output that I get from Read All Bytes.vi and I'm trying to convert the output to binary so that I can handle the masking of the first 3 bits of my 16 bit register (and verify that my output makes sense).

If you take a look at the image below that I have taken from the 9808 spec sheet, it shows that the 4th bit is the sign bit and the rest is the actual data in 2's compliment. I'm currently at a loss as to how I can return the value of the register in binary, or at least mask the first 3 bits, use the 4th bit to reveal the sign to yield a temperature in deg C.

This is all a learning experience to me and I'm having a lot of fun with ACC4LV, I just reach a dead end every now and then. - Or maybe it's not so much a dead end as not knowing how to open the next door!

I would appreciate anyone's input on the matter.

Thanks,

Kbet

Attachments
November 26, 2015
10:16 am
Avatar
Adrian
Germany
Member
Forum Posts: 21
Member Since:
August 3, 2015
sp_UserOfflineSmall Offline

Hi,

in the datasheet of MCP9808 is a source code example. You can use this in your own header or "c" file. These files can be used in the Arduino compatible Compiler. Please read the manual. Chapter: "Porting an Arduino Library to LabVIEW".

There you can see all possibility's to use C-Code in the compiler. I think you can solve very easily your problem.

 

Adrian

November 28, 2015
12:20 am
Avatar
Steffan
Admin
Forum Posts: 305
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

You can also do the masking in straight LabVIEW G language.  You'll need to read up on standard LabVIEW bitwise programming and the boolean and numeric palettes.  You can use things like AND, OR, and shift and rotate primitives to do what you want.

November 30, 2015
7:34 pm
Avatar
Kbet
Member
Forum Posts: 4
Member Since:
March 19, 2015
sp_UserOfflineSmall Offline

Adrian,

I thought this operation might come to porting the library to arduino, but I'm not familiar with the tool. So, I'm dragging my feet on that topic right now. I'll have to go through the add and subtract examples and work my way along.

 

Seffan,

Thanks for the tip on bitwise operators. Didn't know that And and Or could be used in Labview as it can be used in C. So, I'm now attempting to 'Split Number' then 'And' the upper byte to check for the sign in bit 12, followed by 'Or' to write the top 4 bits to '0'.

I'll let you know how it goes.

Kbet

Forum Timezone: UTC 0

Most Users Ever Online: 33

Currently Online:
3 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

John: 18

RTSLVU: 15

Dan6077: 11

Member Stats:

Guest Posters: 0

Members: 80

Moderators: 0

Admins: 3

Forum Stats:

Groups: 1

Forums: 2

Topics: 58

Posts: 289

Newest Members: Travlissah, viktorIcera, HowardClouG, Dianecet, Produktnaodchudzaniex

Administrators: geadmin: 5, filipealtoe: 35, Steffan: 89