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

Writing to specific memory address robot c
http://robotc.net/forums/viewtopic.php?f=52&t=10378
Page 1 of 1

Author:  RoboRams [ Wed Jan 28, 2015 1:13 am ]
Post subject:  Writing to specific memory address robot c

Hey I'd like to utilize some of the functionality in this document:

http://www.hitechnic.com/blog/wp-conten ... cation.pdf

And as such I need to write to a specific memory address in robot c. Can somebody post an example of how to do so?

Author:  FTC_359 [ Wed Jan 28, 2015 9:23 am ]
Post subject:  Re: Writing to specific memory address robot c

You can take a look at our library here for examples on how we were able to communicate with the Hi-Technic motor and servo controllers.

Author:  RoboRams [ Wed Jan 28, 2015 12:52 pm ]
Post subject:  Re: Writing to specific memory address robot c

Sorry it's not quite to me on how to address the motor control block (I am trying to set the NTO bit on both channels to 1).

Author:  FTC_359 [ Wed Jan 28, 2015 5:04 pm ]
Post subject:  Re: Writing to specific memory address robot c

This is assuming that HT's mapping of the byte considers the least significant bit as bit place 0.

Code:
#include "common.h"

#define HTMC_I2C_ADDR_1     0x02 //Address of the first controller
#define HTMC_I2C_ADDR(CHAN) HTMC_I2C_ADDR_1*CHAN

#define HTMC_OFFSET         0x44
#define HTMC_MODE(CHAN)     (CHAN-0x01)*0x03

#define HTMC_O_NTO          0x10 //00010000

tByteArray HTMC_I2CRequest;
tByteArray HTMC_I2CReply;

bool HTMC_NTO(tSensors link, byte channel){
    memset(HTMC_I2CRequest, 0, sizeof(tByteArray));
    ubyte mask[2] = {0, 0};
   
    HTMC_I2CRequest[0] = 2;
    HTMC_I2CRequest[1] = HTMC_I2C_ADDR(channel);
    HTMC_I2CRequest[2] = HTMC_OFFSET + HTMC_MODE(1);
   
    if(!writeI2C(link, HTMC_I2CRequest, HTMC_I2CReply, 1))
        return false;
    mask[0] = HTMC_I2CReply[0] ^ HTMC_O_NTO;
   
    memset(HTMC_I2CRequest, 0, sizeof(tByteArray));
   
    HTMC_I2CRequest[0] = 2;
    HTMC_I2CRequest[1] = HTMC_I2C_ADDR(channel);
    HTMC_I2CRequest[2] = HTMC_OFFSET + HTMC_MODE(2);
   
    if(!writeI2C(link, HTMC_I2CRequest, HTMC_I2CReply, 1))
        return false;
    mask[1] = HTMC_I2CReply[0] ^ HTMC_O_NTO;
   
    memset(HTMC_I2CRequest, 0, sizeof(tByteArray));
   
    HTMC_I2CRequest[0] = 3;
    HTMC_I2CRequest[1] = HTMC_I2C_ADDR(channel);
    HTMC_I2CRequest[2] = HTMC_OFFSET + HTMC_MODE(1);
    HTMC_I2CRequest[3] = mask[0];
   
    if(!writeI2C(link, HTMC_I2CRequest))
        return false;
   
    memset(HTMC_I2CRequest, 0, sizeof(tByteArray));
   
    HTMC_I2CRequest[0] = 3;
    HTMC_I2CRequest[1] = HTMC_I2C_ADDR(channel);
    HTMC_I2CRequest[2] = HTMC_OFFSET + HTMC_MODE(2);
    HTMC_I2CRequest[3] = mask[1];
   
    if(!writeI2C(link, HTMC_I2CRequest))
       return false;
   
    return true;
}

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