by adrianovrm » Tue 14. Apr 2015, 01:54
Ok,
L discover the problem , l was making some mistakes at the receiveing the packet and handleing it at aruino side. SO to help help anyone to get easy with this l will explain a bit more how a done that :
LEts go :
If you need to put checksum onto your arduino code , think this way. lets say that your data packet at uso is
X~A01~~A02~~A03~~A04~~A05~~A06~
than A01 to A05 are 16 bits binary and A06 is a 8 bits binary . So you haveL
X (STX - start byte) - 1 byte
A01 to A05 = 10 bytes
A06 = 1 byte
TOtal bytes 12 bytes , but to add checksum you will have to add one more byte , at uso page is says that the format is ~cxx~ where xx is number of bytes of the data packet minus the checksum byte itself. in thsi example this is equal to 12. so , the data packet will be like this now :
X~A01~~A02~~A03~~A04~~A05~~A06~~c12~
well then you just use this checksum procedure:
void CheckChecksum() // Atmel chips have a comport error rate of 2%, so we need here a checksum
{
volatile int z;
xCalcchecksum = 0x01 ^ 0x59; // X foi retirado do vetor // tem que ser reinserido para
// o correto calculo
// 13 bytes com checksum que sera comparado - nao entra na conta [xReadQuantBytes -1] = checksum
// [xReadQuantBytes -2] igual ultimo byte valido 0
for(z=0; z < xReadQuantBytes - 2; z++)
{
xCalcchecksum = xCalcchecksum ^ xXSIMData[z];
}
if (xCalcchecksum!=xXSIMData[11])
{
errorcount++;
}
}
the above procedure was capture form X-pid.ino and adjusted to my needs.
most variables here l made them global, just to ease my test, not the best programminhg tecniche, but l was wanting to make it works asap.
xXSIMDATA is a array of 13 possitions where a receive all my data packet.
pay attention the checksum received from x-sim is onto xXSIMData[11] , is should be onto xXSIMData[12] .l make this , cause in another part of my program a rip off the X first byte received from the array. pay attention that at start of the procedure l put it back onto calculations 0x59(hexa)= 89(dec) ="X"(ascii). last tip. look the xor with 1 -> 0x59 ^ 0x01. this operation was missing at function l could grabfrom xpid.ino. and from my reading before, it is need to right calculate the checksum. then, at first trial of the program l notice that xsim received checksum, at arduino, was 1 higher than my calculated value. so l remenber that tip, this is the big jump of the dead cat. Enjoy guys.