%Write memory
%
%Write one byte to the controllers volatile memory.
%
%The addressable memory range is 0..0xFF, but not all addresses are
%writable. When a write attempt fails the controller returns 0x00,0x00.
%### TODO: Tabulate writable addresses. ###

function writeMem(H,addr,data)

globalVar;
servoReturn1 = 3;   %valores que se esperam obter do servo nesta operação
servoReturn2 = 3;

command = WRITE_MEM;
param1 = addr;
param2 = data;
checksum = 256 - mod((STARTBYTE+command+param1+param2),256);

sendMessage(H,command,param1,param2,checksum);
[return1,return2]=readMessage(H);

if((servoReturn1 ~= return1) || (servoReturn2 ~= return2))
    err = ERR_WRITE_MEM;
    errfcn(H,err);
end
