USO output to an Arduino

Open a thread for a question about the simulator control software.
If you cannot receive any data in the input setup use the upper two forums!

Re: USO output to an Arduino

Postby sirnoname » Mon 13. Apr 2015, 20:07

As told, I do not trust your written A06.
Use the serial port monitor and check what X-Sim sends.
http://www.heise.de/download/free-seria ... nitor.html
If a answer is correct or did help you for a solution, please use the solve button.
User avatar
sirnoname
Site Admin
 
Posts: 1829
Images: 45
Joined: Thu 1. Sep 2011, 22:02
Location: Munich, Germany
Has thanked: 35 times
Been thanked: 128 times

Re: USO output to an Arduino

Postby adrianovrm » Mon 13. Apr 2015, 22:10

Hey man , l made the checksum counts for one default central positions start data packet ,vale of checksum Was 166 por central positions , tem valor that xsim is sending tô me is 167 nas my calcularmos at arduino are given 167 ,só l guess is the arduino calcs there are with problems ,l will de bug and discover the lastbissue ,l dont use you functiin checksum yet ,l use the x-pid checksum , l will discover my copy and paste erro,and reportagem too you when final work, l near the solution
adrianovrm
X-Sim Supporter
 
Posts: 214
Joined: Tue 20. Nov 2012, 07:35
Has thanked: 0 time
Been thanked: 1 time

Re: USO output to an Arduino

Postby 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.
adrianovrm
X-Sim Supporter
 
Posts: 214
Joined: Tue 20. Nov 2012, 07:35
Has thanked: 0 time
Been thanked: 1 time

Previous

Return to Converter questions

Who is online

Users browsing this forum: No registered users and 1 guest