So you need to use the standard method of I2C communication, not this short cut.
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
// #include "nxcio.h"
void TXMotorOn(byte NXTport, byte TXmotor, char percentage)
{
const byte retLen = 0;
byte modeMsg[];
byte powerMsg[];
byte devAddr, modeReg, powerReg;
char result;
devAddr = (TXmotor+2)&14;
modeReg = 0x44 + (TXmotor % 2)*3;
powerReg= 0x45 + (TXmotor % 2);
// Create the message arrays
ArrayBuild(modeMsg, devAddr, modeReg);
ArrayBuild(powerMsg, devAddr, powerReg, percentage);
// Send the first message as soon as the bus is ready
while ((I2CCheckStatus(NXTport) == STAT_COMM_PENDING) && (I2CCheckStatus(NXTport) != NO_ERR)) Yield();
if(I2CWrite(NXTport, retLen, modeMsg) != NO_ERR)
return;
// Send the second message when the first one is done
while ((I2CCheckStatus(NXTport) == STAT_COMM_PENDING) && (I2CCheckStatus(NXTport) != NO_ERR)) Yield();
if(I2CWrite(NXTport, retLen, powerMsg) != NO_ERR)
return;
}
task main(){
TXMotorOn(0, 1, 50);
Wait(2000);
TXMotorOn(0, 1,-50);
Wait(2000);
TXMotorOn(0, 1, 0);
Wait(2000);
while (true);
}
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
long MyWriteI2CRegister(byte port, byte address, byte register, byte regvalue) {
const byte retLen = 0;
byte msg[];
// Create the message array
ArrayBuild(msg, address, register, regvalue);
// Send the first message as soon as the bus is ready
while ((I2CCheckStatus(port) == STAT_COMM_PENDING) && (I2CCheckStatus(port) != NO_ERR)) Yield();
return I2CWrite(port, retLen, msg);
}
Again, not tested
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
doc-helmut wrote:will it be possible to pass also a int or a long as a regvalue (e.g., for passing encoder values)?
Nope, as long as NXC doesn't support function overloading it can't be done with a single function name.
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
ok, thx, but I must admit: it is even much harder than I thought with the I2C motor program for Tetrix
But that's not a WriteI2CRegister compile issue any longer.