Some functions used in bluevmega.c. I've extracted what you need to see to undertsand the issue.
static int readpkt(unsigned char *buf)
{
unsigned char len, ix;
buf[0] = 0;
for (;;) {
while (buf[0] != 0xaa) // SOF
{
// GLOW: start to loop here: turning turning turning turning if it's with hwsetup() Working well with init() !!!!!!!!!!!
buf[0] = readv1rx();
}
buf[1] = readv1rx(); // destination
......
extern volatile unsigned char v1head, v1tail, inhead, intail;
extern unsigned char v1buf[], inbuf[];
// LOW LEVEL ROUTINES FOR ARDUINO
// Read one character from the V1 data stream
static int readv1rx(void)
{
while (v1head == v1tail)
sleep_mode();
return v1buf[v1tail++];
}
I hope it's understandable.
Any idea? Thx.