Im sure im going to annoy everyone today with amount of posts.
Ive taken the suggests from previous post and had a go at implementing it. Code is below.
Problem is if i assign n.x = 0xABCD; in the union in my function the output is perfect. However is i change it to n.x = Index then it only picks up the CD not the AB. My code is put below.
Code:
#include <stdio.h>
char SendData[8];
static void MakingSDOmessage(char Index, char SubIndex, int Value);
int i;
main()
{
MakingSDOmessage(0xABCD, 0xe3, 0);
for ( i=0; i < 8; i++)
printf("SendData[%d] = 0x%x\n", i, SendData[i]);
while(1)
{
}
}
static void MakingSDOmessage(char Index, char SubIndex, int Value)
{
union number {
short int x;
char bytes[2];
};
union number n;
n.x = 0xABCD;
SendData[1] = n.bytes[0];
SendData[2] = n.bytes[1];
SendData[3] = SubIndex;
}