Device with custom I2c Protocol?

Status
Not open for further replies.

bg123

New member
Hey everyone. I am trying to interface between a Teensy 3.2 and a stepper motor we use at my work with what I believe has a non-standard I2C protocol and I can't figure out how to construct the I2C functions. In the protocol we use, I have to send the following in a series of bytes:
- Byte 1: Device address
- Byte 2: Message length in bytes (6 bytes in this example)
- Byte 3: more config info
- Byte 4: Message code
- Byte 5 and 6: CRC-16 for the above 4 bytes.

The device will then respond with:
- Byte 1: Device Address
- Byte 2: return message length
- Byte 3: config info
- Byte 4: message code
- Byte 5 and 6: Return message CRC

I'm hung up because this all needs to happen as part of a single call, but the build-in Wire functions only allow for the address + number of bits to read, and no options to put in the other 5 fields mentioned above after the device address. The write function would let me write all this data and I could use endTransaction(), but when I go to use requestFrom(), it is going to rebroadcast the device address which doesn't follow the protocol, I'm supposed to start reading immediately after the 6th bytes in the first block of bytes. Is there a way to do this using the built-in functions, or would I need to write my own Wire functions which can send the bytes before starting the read portion?
 
A hardware solution: you could gate SDA and SCL with an analog mux or 2 FET's. You enable the I2C bus and send your data. You disable the bus and send the read command which your slave will not see. Enable the bus and read back your data. I think this will work as the slave shouldn't start sending any data until it sees the clock.

A software solution: you could tie SDA and SCL to a couple of other input pins. You will then use the Wire library to send data, and use a function you need to write to receive data. A bit bang read function.
 
Thanks rcarr and BriComp for replying. I ended up just following the normal Wire.write() transaction and then Wire.requestFrom() and the motor replied with the expected response (starting after the address byte). Looks like the motor is happy to gloss over the fact that both the master and slave are writing data on the bus at the same time. Wondering if maybe the fact that they are both writing the same thing at the same time (the address of the slave), but not going to complain! I do have a logic level converter in between, but not sure if that matters. Cheers.
 
Status
Not open for further replies.
Back
Top