7 Replies Latest reply on Jan 15, 2017 3:35 AM by r.dijkstra05_1488816

    I2C Materwritebuf not working inside a function

    r.dijkstra05_1488816

      Hello,

         

      I have the following piece of code which is working fine on the main thread

         

      uint8 MOTOR_bufsize=3
      uint8 xSpeedLSB = value & 0xff;
      uint8 xSpeedMSB = value >> 8;
      uint8 MOTOR_waarde[3] = {0x0, xSpeedLSB, xSpeedMSB};
      //set MOTOR
      I2C_MOTOR_MasterClearStatus(); /* Clear any previous status */
      I2C_MOTOR_MasterWriteBuf(MOTOR_I2C_SLAVEADRES, MOTOR_waarde, MOTOR_bufsize, I2C_MOTOR_MODE_COMPLETE_XFER);

         

      But as soon I put the same lines into a function, nothing happens when the function is called. The function is shown below;

         

      void set_speed(axis, speed) {
      if (axis == Xaxis) {
        uint8 channel = 0x0;
        }
      uint8 bufsize=3;
      uint8 SpeedLSB = speed & 0xff;
      uint8 SpeedMSB = speed >> 8;
      uint8 MOTOR_waarde[3] = {channel, SpeedLSB, SpeedMSB};
      I2C_MOTOR_MasterClearStatus(); /* Clear any previous status */
      I2C_MOTOR_MasterWriteBuf(MOTOR_I2C_SLAVEADRES, MOTOR_waarde, bufsize, I2C_MOTOR_MODE_COMPLETE_XFER);

      }

         

      the function is called by:

         

      set_speed(Xaxis, value);

         

      in which Xaxis is an integer (0) and value is an integer between 0 and 1023.

         

      The function is initialized by:

         

      void set_speed(int axis, int speed);

         

      Can anybody help me on my way why my function does not work?