View previous topic :: View next topic |
Author |
Message |
SimpleGuy
Joined: 12 Dec 2008 Posts: 7
|
Problem with Arrays |
Posted: Thu Apr 02, 2009 11:01 am |
|
|
Hi All,
I have 2 loops in my code. One loop that fills an array, the other loop prints it out. See code below. If I take out the array and output the numbers as I get them, I get the data I expect; but with the array, I get a data stream that is shaped like "saw wave" out. Why is the data not consistent? What am I doing wrong?
Code: | #include <30F5011.h>
#device *=16
#device ICD=true
#fuses EC, NOWDT
#use delay(clock=40000000)
#use rs232 ( FORCE_sw, baud=460800, xmit=pin_F5, rcv=pin_F4, INVERT)
#use SPI(master, DI=pin_f2, clk=pin_f6, bits=16, mode=0, msb_first)
for(I3=0; I3<=1023; I3++)
{
data[I3]=spi_xfer(); //Read 1024 16bit nubers and put in array
}
for (I=0; I<=1023; I++)
{
intMSB = make8(data[I],1); //write 1024 16bit
intLSB = make8(data[I],0);
putc(intMSB);
Putc(intLSB);
} |
Thanks for the help. |
|
|
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Thu Apr 02, 2009 12:27 pm |
|
|
What is the type of I and I3? Are they both unsigned int16? _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
Guest
|
|
Posted: Thu Apr 02, 2009 1:05 pm |
|
|
yes |
|
|
ECACE
Joined: 24 Jul 2006 Posts: 94
|
|
Posted: Thu Apr 02, 2009 1:07 pm |
|
|
Can you post more of your code where you define the array? _________________ A HW Engineer 'trying' to do SW !!! Run!!! |
|
|
SimpleGuy
Joined: 12 Dec 2008 Posts: 7
|
|
Posted: Thu Apr 02, 2009 1:19 pm |
|
|
refining my problem. I start going step by step. I run into the problem when i use a 16bit array. My input doesn't match my output.
#include <prototype.h>
void Main()
{
unsigned int16 data[6];
unsigned int16 i;
unsigned int8 temp1, temp2;
while(true)
{
for (i=0; i<=4; i++)
{
temp1=getc();
temp2=getc();
data[i]=(make16(temp1, temp2));
printf(" %u ",i);
}
printf("\n\r output from array\n\r");
for (i=0; i<=4; i++)
{
temp1=make8(data[i],0);
putc(temp1);
temp1=make8(data[i],1);
putc(temp1);
}
}
}
iF I input 444444
i get this out.
0 1 2 3 4
output from array
4\4^4`4b4d |
|
|
|