I2C Generic to MD23
Navigates to RoboticsConnection.com Home RoboticsConnection.com HomePage
RoboticsConnection User Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



I2C Generic to MD23 Expand / Collapse
Author
Message
Posted Wednesday, March 26, 2008 11:45 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: Thursday, April 03, 2008 8:22 PM
Posts: 16, Visits: 24
Jason,

Thanks for your response to my earlier post.  I'll pull this out into a separate topic in case it might help someone else.  I saw the I2CDevice object and figured that would be the way to go, for communicating with the not-yet-supported MD23 I2C device. 

However, I got a little hung up with the I2C byte sequences that you mention.  The MD23 documentation discussing the registers, etc., is at http://www.robot-electronics.co.uk/htm/md23tech.htm and it describes "first send a start bit, the module address (0xB0 for example) with the read/write bit low, then the register number you wish to read [there is a list of registers, 0-16, in a table there].  This is followed by a repeated start and the module address again with the read/write bit high (0xB1 in this example).  You are now able to read one or more registers."

Being a relative newbie to I2C and serial communication, I haven't quite been able to translate that into C#, let alone English

What i2cd.Write() command(s) would I issue to this (assuming it's at its default I2C address, 0xB0) to read the battery volts (register 10) and write a mode of "2" to register 16?  [A read example and a write example should be enough to get me off to the races!]

Thanks!

Post #247
Posted Wednesday, March 26, 2008 5:42 PM


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Administrators
Last Login: Today @ 6:22 AM
Posts: 277, Visits: 407
Thanks for opening this thread up!

If you wanted to read the values of the MD23, you would basically send a write command to the address of the device, followed by the register you want to read, then you would issue an additional write to the same address, along with the number of bytes that you want to read from that register, which in the case of the battery is 1 byte.

void ReadMD23Battery()
{
        i2cd.Write(0xB0, "10");
        byte voltage = Convert.ToByte(i2cd.Read(0xB0, "1"));
        
        // use voltage for whatever
        
        Console.WriteLine("Battery Voltage: {0}", voltage)
;

If you wanted to simply write a value to the mode bit, then you would simply send the following:

void WriteMD23Mode(byte mode)
{
       string cmd = String.Format("15 {0}", mode);
       i2cd.Write(0xB0, cmd);
}

Please note that I cannot debug this as we don't have an MD23.   I'm sure you can take it from here...The .NET lib and Serializer firmware hide a lot of the tedious stuff you typically have to deal with when using I2C devices (e.g. start bits, etc.), so you don't have to worry about it (which is the whole point).

Please note that the "i2cd" object would be defined somewhere in your application.  It's basically just an I2CDevice().

Let us know if this worked for you.

I'll add more documentation on the Generic I2C interface to the Serializer .NET Lib example too.

Best Regards!

Jason Summerour
President,
Summerour Robotics Corporation
Microsoft MVP
www.roboticsconnection.com

Post #249
Posted Wednesday, March 26, 2008 8:31 PM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: Thursday, April 03, 2008 8:22 PM
Posts: 16, Visits: 24
Great information, thanks for all the help!  I believe I understand the examples you provided, and I look forward to trying it out soon.  (Still need to get a power supply for my MD23 so can't check it out right away).
Post #254
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: jsummerour

Permissions Expand / Collapse

All times are GMT -8:00, Time now is 9:18am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.140. 10 queries. Compression Disabled.