I have some problem with a function returning a long, which I don't seem
to be able to reproduce in a simple example.
I have this function defined in aad7789.c
unsigned long ad7789Read(unsigned char ch, unsigned long *data)
{
unsigned long d;
unsigned char rx;
P1OUT &= ~0x01; /* CS */
/* AD7789 mode single converison, unipolar */
ad7789ModeWrite(ch & 0x03, 0x86);
#ifdef TARGET
while ((P3IN & 0x04) != 0); /* Wait for data ready */
#endif
rx = ad7789StatusRead();
/* Read the data register */
ad7789CommWrite(0x38 | (ch & 0x03));
rx = ad7789SpiTxRx(0xff);
d = rx;
rx = ad7789SpiTxRx(0x00);
d = (d << 8) + rx;
rx = ad7789SpiTxRx(0xff);
d = (d << 8) + rx;
P1OUT |= 0x01; /* CS */
*data = d;
return d;
}
and a function calling this from cmd.c
void Ad7789Cmd(void)
{
unsigned char chan;
unsigned long data, d;
char *p;
p = Line;
p = GetNextParameter(p); /* find the next param if there is one */
chan = (unsigned char)stoi(p, 10);
ad7789PowerUp();
data = ad7789Read(chan, &d);
printf("AD7789 data %ld\r\n", data);
ad7789ShutDown();
printf("AD7789 d %ld\r\n", d);
}
now the value returned to data seems to be the upper 16 bits of the
return value, where as d (passed as a pointer) is correct.
The assumbler listing for the above function is
.LM32:
mov r4, r15
add #llo(6), r15
mov.b @r4, r13
mov r15, r14
mov r13, r15
call #ad7789Read
mov r15, 2(r4)
mov 2(r4), 2+2(r4)
rla 2+2(r4)
subc 2+2(r4), 2+2(r4)
inv 2+2(r4)
I don't understand what the last 4 instructions do? and it never uses
the value returned in r14.
the compile line for ad7789.c are
msp430-gcc -save-temps -DTARGET -mmcu=msp430x149 -g -Wno-main
-I./include -Ibl/include -Iblbl/include -Iblblbl/include -c
lib/ad7789/ad7789.c -o lib/ad7789/msp430x149/ad7789.o
and for cmd.c are
msp430-gcc -save-temps -DTARGET -g -Wno-main -mmcu=msp430x149
-I./include -Ibl/include -Iblbl/include -Iblblbl/include -c
multiSensor/cmd.c -o multiSensor/msp430/cmd.o
does anyone have any ideas?
--
Peter Jansen
STS
Australian Antarctic Division
Channel Highway
Kingston
TAS 7050
AUSTRALIA
Ph (03) 62 323 533
Fax (03) 62 323 351