volatile keyword needed when only reading in ISR?

Hi all-

I have an ISR that reads values from a byte array that is loaded from the main program loop. The main loop only writes to the array; the ISR only reads from it, never writes. Is it still necessary to use the volatile keyword? I ask because the array is passed by pointer to the SD card reading function that actually fills the buffer, but one (apparently) cannot cast a volatile byte* to a byte* or even a volatile byte* to a void*.

I've considered using an intermediate buffer and memcpy(), but would rather avoid the extra clock cycles this would require.

Background: I'm working on a program that reads data from an SD card and outputs it to several pins at 20-30 kHz. I have enough time to do this (I think, I haven't tested reading with the ISR running yet). The buffer is larger than a block on the SD card, so the SD reading can load one part of the buffer while the ISR reads from another. I can't post actual code since I'm not at that machine, but the basic structure is this: loop: Check flag for load status in part of buffer. If read, fill it with new data, and set flag appropriately. ISR: Read the next set of values from the buffer, output them. If we crossed a "block boundary" in the buffer, set a flag indicating the previous block is now empty.

Thanks for any help, or nudges toward reading that'll help.

I ask because the array is passed by pointer to the SD card reading function that actually fills the buffer, but one (apparently) cannot cast a volatile byte* to a byte*

Sure one can.

volatile byte b[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

void setup()
{
}

void loop()
{
  test((byte *)b);
}

void test(byte d[])
{
}

This compiles on 0022 on Windows 7 64 bit.

Ah, so my problem was relying on the compiler to do the cast automatically during the assignment statement, rather than doing an explicit cast myself. That is, doing

volatile byte buffer[1024];
byte* bufferPtr = &buffer[512];

instead of

volatile byte buffer[1024];
byte* bufferPtr = (byte *)&buffer[512];

This probably should have occurred to me last night. I'll try it out when I get home. Thanks for the help!

Ah, so my problem was relying on the compiler to do the cast automatically during the assignment statement, rather than doing an explicit cast myself.

Right. The error message says that there is no implicit cast defined, not that a cast can't be performed. Explicit casts can be performed, as long as you are aware of what the cast is doing.

In the case of casting around volatile and const keywords, the cast will always work, and always produce the correct results. Casting from one type to another may not always work.