View unanswered posts | View active topics It is currently Wed Sep 23, 2020 7:48 pm






Reply to topic  [ 8 posts ] 
i2c hbridge 
Author Message
Rookie

Joined: Thu Nov 05, 2009 12:35 pm
Posts: 4
Post i2c hbridge
Are there any good guides with i2c programing with robot c.
I am trying to use the digital output of a PCF8574 to control the logic inputs of an hbridge.


Thu Nov 05, 2009 12:41 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: i2c hbridge
Have a look at this articles I wrote: http://mightor.wordpress.com/2008/06/30 ... -pcf8574a/, you might also be interested in http://mightor.wordpress.com/2008/07/05 ... he-clones/ and http://mightor.wordpress.com/2008/06/23 ... -pcf8574a/

The source code there is quite old and hasn't been tested with new releases. I'll add a driver for it to the Driver Suite as soon as possible.


Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Nov 05, 2009 1:04 pm
Profile WWW
Rookie

Joined: Thu Nov 05, 2009 12:35 pm
Posts: 4
Post Re: i2c hbridge
Awesome, thanks for the quick reply. This will at least get me started.

Just a few questions though.

I am not very familiar with C what does the following line do?
Code:
msg = (enabled) ? (0x02|0x04) : 0x0;

Mainly I don't get the syntax of (enabled) ? (0x02|0x04) : 0x0

Also what does each of the hex values correspond to. You use a few of them 0x01, 0x02, 0x04, 0x70, 0x80 etc. From my understanding 0x01 sends a 1 to P0, 0x02 sends a 1 to p1, and 0x04 sends a 1 to p2 but thats about it. Is there a table of hex values and what they mean?


Thu Nov 05, 2009 1:43 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: i2c hbridge
Code:
msg = (enabled) ? (0x02|0x04) : 0x0;

Is identical to saying
Code:
if (enabled == true) {
  msg = (0x02|0x04);
} else {
  msg = 0x0;
}


You can use the windows calculator to convert between decimal and hexadecimal :)

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Nov 05, 2009 2:32 pm
Profile WWW
Rookie

Joined: Thu Nov 05, 2009 12:35 pm
Posts: 4
Post Re: i2c hbridge
I know how to convert hex to decimal. I want to know what it does when you send the hex value to the i2c chip. For example if i write 0x01 to the i2c chip how do i know that it turns p0 on?


Thu Nov 05, 2009 4:29 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: i2c hbridge
For that stuff, you need to refer to the datasheet :)

You can find a copy of it here: [LINK].

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Thu Nov 05, 2009 4:36 pm
Profile WWW
Rookie

Joined: Thu Nov 05, 2009 12:35 pm
Posts: 4
Post Re: i2c hbridge
I still don't quite get it. The datasheet doesn't says what message should i send to the i2c chip to turn a pin on.
Also for your code you have
Code:
sendI2CMsg(S1,PCF8574A_I2C.i2cMessageSize,0);

You are only using MessageSize as a parameter, how does the program know what message to send to the i2c chip.


Thu Nov 05, 2009 5:57 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: i2c hbridge
xdarkfluxx wrote:
I still don't quite get it. The datasheet doesn't says what message should i send to the i2c chip to turn a pin on.
Also for your code you have
Code:
sendI2CMsg(S1,PCF8574A_I2C.i2cMessageSize,0);

You are only using MessageSize as a parameter, how does the program know what message to send to the i2c chip.

From the Philips datasheet:
Quote:
7.3 Quasi-bidirectional I/Os
A quasi-bidirectional I/O can be used as an input or output without the use of a control signal for data direction (see Fig.15). At power-on the I/Os are HIGH. In this mode only a current source to VDD is active. An additional strong pull-up to VDD allows fast rising edges into heavily loaded outputs. These devices turn on when an output is written HIGH, and are switched off by the negative edge of SCL. The I/Os should be HIGH before being used as inputs.

To switch a pin on, you write a 1 to it. You can use a pin as an input by writing a 1 to it and then reading its value.

Code:
sendI2CMsg(S1,PCF8574A_I2C.i2cMessageSize,0);

That means that I am using the PCF8574A_I2C.i2cMessageSize as the beginning address, it's basically a pointer. I probably could've used
Code:
sendI2CMsg(S1,PCF8574A_I2C,0);

too. The first byte in that struct contains the size of the message. So my guess is that once it knows how many bytes the message is, it will copy the specified number of bytes after the size specifications into a buffer to be sent to the I2C device in question.

In any case, this w/e I'll try to write an easy to use library for this chip and add it to the driver suite. Are you using the Mindsensors PCF8574A experimentation board or your own home made circuit? If the case is the latter, I can really recommend you switch to the MCP23008, it's a MUCH better chip and much easier to use. A driver for it is already included in my suite. The code I wrote that you're using now was written quite a while ago (almost 1.5 years). I'd probably do things a little differently now :)

If you're still unsure, ask and I'll try to answer as well as I can :)

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Nov 06, 2009 2:22 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.