Pointers and dereferencing the data

I’m trying to read data collected from an ADC chip on one of the PRU’s of the Beaglebone Black and I’m having difficulty interpreting what I’m seeing. Using Derek Molloy’s website as a guide, I use the commands

unsigned int spiData[3];

spiData[1] = readFileValue(MMAP1_LOC “addr”);

to get the location to store the data. The SPI code runs and then I spin through a loop looking at the data. However, I’m confused as to the proper coding to display the data.

It seems to me that spiData[1] holds the address of the external memory and so should be an integer pointer. So I think I should just be able to dereference that variable to get to the data. However, I’ve tried several methods with compiler errors such as

error: invalid type argument of type unary ‘*’ (have ‘int’) or
warning: assignment makes integer from pointer without a cast

For example the following gives the unary error.

int p;
p = spiData[1];
for (i=0; i < numberSamples; i++)
printf(“Point: %d \t Data: %d\n”, i++, (int *)*p);
p = p + 2;

If I replace (int *)*p with (int *)&p

the program compiles and runs but returns the same value for each reading. However, running the program again gives a different value but still the same value for each reading. Obviously, I’m misunderstanding pointers

I really think I’m getting data placed at the value stored in spiData[1] but I’m just not looking at it right. Can anyone give me an example of how I should be dereferencing that address to get to the data?


Mike Pitman