View unanswered posts | View active topics It is currently Sun Jun 24, 2018 9:10 am






Reply to topic  [ 4 posts ] 
Writing to specific memory address robot c 
Author Message
Rookie

Joined: Fri Jan 09, 2015 4:05 pm
Posts: 6
Post 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?


Wed Jan 28, 2015 1:13 am
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post 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.


Wed Jan 28, 2015 9:23 am
Profile
Rookie

Joined: Fri Jan 09, 2015 4:05 pm
Posts: 6
Post 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).


Wed Jan 28, 2015 12:52 pm
Profile
Rookie

Joined: Tue Jan 13, 2015 10:48 pm
Posts: 23
Post 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;
}


Wed Jan 28, 2015 5:04 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.