0
\$\begingroup\$

I hope that I am phrasing this correctly but here goes. I have been building a service for MSRDS to run my prototype board. People have probably seen me ask questions about this before. I have been pretty successful with it and I have an interface that lets me write and read from it but I am not sure how to deal with addresses like 0x53-0x54 where they use all 8 bits from 53H and then 2 more from 0x54.

For example I can set the address 0x4D (which controls whether or not the digital ports are input or output) to 0x01 and then set 0x4E to 0x01 and the LED I have plugged into the bread board lights up - that's easy because in both cases I am only dealing with a single 8 bit address my problem arises when I am trying to set the voltage on analog output O0. I thought I could just send two commands, the first setting the address of 0x55 to 0xFF and then setting 0x56 to 0xC0. I have tried various combinations of this however can't ever get the voltage above about 1 volt and I think it is because I am not setting the values properly.

Hopefully I have made this clear enough that someone can enlighten me as to what needs to be done in order to better understand what I am doing.

This is the code that actually handles sending the message over USB serial link to the I2C device. It's sort of complex and not really clear because it is posting to a service (the brick service), I have spent hours with it but I suspect it won't tell anyone else much off the bat. It's from a modified version of the NXT source code included in MSRDS samples. That being said I can tell you that it works pretty well when I am dealing with just one 8 bit address. Also not - it's called ReadFromI2cAddressHandler because with the lego USB protocol you always get back a 16 bit padded response - in the case you want to just write some data you just ignore it because it's all zero's anyway. If you want to see more of the code it's on my github account.

 [ServiceHandler(ServiceHandlerBehavior.Exclusive)]
    public virtual IEnumerator<ITask> ReadFromI2cAddressHandler(ReadFromI2cAddress readRequest)
    {
        var write = new LegoLSWrite
        {
            Port = _state.SensorPort,
            TXData = readRequest.Body.TxData,
            ExpectedI2CResponseSize = readRequest.Body.ExpectedResponseSize
        };


        Activate(Arbiter.Choice(_legoBrickPort.SendNxtCommand(write),
                                EmptyHandler,
                                f => LogInfo(f.ToException().InnerException + " " + f.ToException().Message)));

        Activate(Arbiter.Receive(false, TimeoutPort(80), EmptyHandler));

        var read = new LegoLSRead(_state.SensorPort);
        Activate(Arbiter.Choice(_legoBrickPort.SendNxtCommand(read),
                                r => readRequest.ResponsePort.Post(new ReadResponse {Bytes = r.CommandData}),
                                f => readRequest.ResponsePort.Post(f)));
        yield break;
    }
\$\endgroup\$
7
  • \$\begingroup\$ I don't expect anyone to "dig around" on the site. It's fairly obvious from that link that it's a development platform which although ancillary gives some context for what I am trying to accomplish. I am sorry if I don't have the technical abilities to distill my question into two or three sentences - I am not sure how to better explain what I am doing with any less information. Sorry I used 6 sentences instead of three. \$\endgroup\$
    – Kenn
    Apr 3 '13 at 14:06
  • \$\begingroup\$ Did you check the "HiTechnic SuperPro Experimenter's Kit Handbook & Sample Programs" for an appropriate example? Is there a circuit diagram and datasheet available, without the need to leave email address? \$\endgroup\$
    – jippie
    Apr 3 '13 at 14:10
  • \$\begingroup\$ Yeah - Their examples work great but they aren't for the MSRDS environment and as far as the technical information or a circuit diagram that webpage is the most you will get form them. Their handbook is more of a "stick this wire here and then click this in the Lego environment", it isn't really too technical. Any emails I have sent asking for more information got no response. again. I can control the thing pretty well I can use the digital ports all day because you only ever need to deal with 8 bits. It's the situations where there are 10 bits used I get tripped up. \$\endgroup\$
    – Kenn
    Apr 3 '13 at 14:24
  • \$\begingroup\$ Can you include your code where you try to write to the device? \$\endgroup\$
    – jippie
    Apr 3 '13 at 14:46
  • \$\begingroup\$ And use '@jippie' or whatever other user's comment you are replying to, so the user gets notified. Otherwise chances are we never return. \$\endgroup\$
    – jippie
    Apr 3 '13 at 14:47
2
\$\begingroup\$

I've never used MSRDS and clicking on "Learn" on the linked site returns "No results" no matter what I do. You also haven't provided any code. So the following is a complete guess.

From what I can tell, you are trying to communicate with a device via I2C and the address you are trying to write to is 10-bits long. You are attempting to do this as:

[Address][Data][Address][Data]

Take a look at the section on 10-bit addressing on the bottom of the I2C Specification.

10-bit addressing can be used together with 7-bit addressing since a special 7-bit address (1111 0XX) is used to signal 10-bit I2C address. When a master wants to address a slave device using 10-bit addressing, it generates a start condition, then it sends 5 bits signaling 10-bit addressing (1111 0), followed by the first two bits of the I2C address and then the standard read/write bit.

write

If the master will write data to the slave device it must send the remaining 8 bits of slave address as the second byte.

If the master will read data from the slave device it must send the complete 10-bit address (two bytes) as for writing, then a repeated start is sent followed by the first address byte with read/write bit set to high to signal reading. After this procedure the data can be read from the slave device.

read

I don't know how to get MSRDS to signal 10-bit addressing. But you need to do that and then do:

[Address][Address][Data][Data]
\$\endgroup\$
2
  • \$\begingroup\$ OMG! Thank you... I have read that document before but clearly missed it or forgot. So yes, that was my exact question. How to deal with ten bit addresses, I am just a hobbyist so please forgive me if I stumble on the language a little as I learn. \$\endgroup\$
    – Kenn
    Apr 3 '13 at 15:36
  • 1
    \$\begingroup\$ @Kenn No problem. And don't worry about Olin. He's always grumpy. :) \$\endgroup\$ Apr 3 '13 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.