Arduino as SPI slave?

Please use [c ode] tags iso quote-tags for posting code (I know there is a bug in the IDE) - you can modify your previous post.

ÿ = char 255 , it means there is no char

the char array must be volatile too.

That said, your ISR has several

  1. sizeof buf => sizeof(buf)
  2. it misses characters if pos >= 149
  3. it can receive characters while loop() has not printed it yet

You must rewrite the ISR.

  • One way is to do double buffering, There is one array that can be printed, and the other can be filled.
  • another way is to use a queue, the ISR fills the queue (including a '\0' if needed) and loop reads from it.

HOpes this helps...