ERROR: ets Jan 8 2013,rst cause:2, boot mode:(3,6)

fatemeh_tabrizi:
I want to collect 6 bytes and put them in buffer[6].

Your approach is flawed. See @Robin2's Serial Input Tutorial for a much better way of doing things.