ROBOTC.net forums
http://robotc.net/forums/

I2c on EV3 with robotC 4.26
http://robotc.net/forums/viewtopic.php?f=1&t=9607
Page 1 of 1

Author:  nxt [ Wed Oct 22, 2014 7:35 am ]
Post subject:  I2c on EV3 with robotC 4.26

Hello,

I am trying to get a mindsensors NXTServo-V2 working with the EV3.
I created a smaller code whitch regenerates the problem. I know it will never work this way, but it compiles and generates an error on the EV3 but not on NXT
Code:
task main()
{
   ubyte volt;
   readI2CReply(S1, &volt, 1);
}

This is the RobotC debugger Exception
Code:
Exception Error in User Program:
   
   Exception Type: 'Real Address Range Exception(59)'
   
   Program Slot: 0, Task ID: main[0]
   Error at PC: Task: main+0x0017
   TaskState: 'Exception'

I know it has something to do with pointers but i cannot figure out what. Any ideas?
To test this code it is not necessary to connect a NXTServo.

some longer piece of code which displays battery voltage of the NXTServo:
Code:
ubyte MS_Servo_SendMsg[5];
char MS_servo_replyMsg[2];
tSensors MS_Servo_port;

const int MS_Servo_ID       = 0xb0;
const int MS_Servo_VbattReg = 0x41;

void servoSetPort(tSensors port)
{
  MS_Servo_port=port;
#ifdef NXT
  SensorType[MS_Servo_port] = sensorI2CCustomFastSkipStates;
#endif

#ifdef ev3
     SensorType[MS_Servo_port] = sensorI2CCustom9V;   //   sensorEV3_GenericI2C
#endif
}

int  servoGetBattV()
{
  // Build the I2C message
  MS_Servo_SendMsg[0] = 2;
  MS_Servo_SendMsg[1] = MS_Servo_ID ;
  MS_Servo_SendMsg[2] = MS_Servo_VbattReg;

//  waitForI2Cbus();
  sendI2CMsg(MS_Servo_port, &MS_Servo_SendMsg[0], 1);
//  waitForI2Cbus();
  delay(10);
 readI2CReply(MS_Servo_port, &MS_servo_replyMsg[0], 1); //Error is generated at this line
//  return 0;
    return(37*(0x00FF & MS_servo_replyMsg[0]));  // 37 is calculated from supply from NXT =4700 mv /128
}

task main()
{
   int batVoltage=0;
   servoSetPort(S1);
   delay(10);
   batVoltage=servoGetBattV();
   displayBigTextLine(3, "%d V",batVoltage);
   delay(100000);
}

/* EV3 error when running code
Exception Error in User Program:
   
   Exception Type: 'Real Address Range Exception(59)'
   
   Program Slot: 0, Task ID: main[0]
   Error at PC: servoGetBattV+0x003B
   TaskState: 'Exception' 
*/

Author:  mightor [ Thu Oct 23, 2014 8:31 am ]
Post subject:  Re: I2c on EV3 with robotC 4.26

Have you tried making the variable volt a single item array? As in ubyte volt[1];

Try that and see if it makes a difference.

= Xander

Author:  nxt [ Thu Oct 23, 2014 9:13 am ]
Post subject:  Re: I2c on EV3 with robotC 4.26

You mean like this?
Code:
task main()
{
   ubyte volt[1];
   readI2CReply(S1, &volt[0], 1);
}


i get the exact same message.
I tryed figuring out how you are handling this in the driversuite, but its a bit too complicated for me.
But thanks anyway. Any other ideas?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/