%Write EEPROM
%
%Write one byte to the EEPROM.
%
%Writable addresses are 0..0x2C. When writing addresses > 0x2C
%every 3rd write attempt will fail, and return 0x00,0x00 ### ? ###

function errn=writeEeprom(H,addr,data)

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

command = WRITE_EEPROM;
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))
    errn=errn+1;
    disp('ERROOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!');
   % err = ERR_WRITE_EEPROM;
    %errfcn(H,err);
end