I'm having some trouble with RF-communication (433MHz) between a attiny85 with 16MHz external oscillator and a Arduino Mega2560.
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
digitalWrite(13, HIGH); // Flash a light to show received good message
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
//Transmitter. Sends integer as 2 bytes once per second
uint16_t data =0; //the integer to send
vw_setup(); // 2000 Bits per sec
uint8_t number ;
number = data;
number = data >> 8; //send 2 bytes
vw_wait_tx(); // Wait until the whole message is gone
delay(1000); //send every second
This code works fine when I use another Mega2560 for transmitting, but not with the attiny85. I assume this is some kind of timing error. That's why I use a 16MHz oscillator to the attiny, to match the Mega2560 in speed.
Since I don't yet own an oscilloscope, I connected LED's to the transmitting pin of both the attiny and the Mega2560 and I got some interesting results. It seems like the attiny takes almost a second to transfer the message when the Mega2560 does it in a couple of milliseconds (if even that long).
I had to change two rows in the VirtualWire-library to get it to compile on the attiny
// Set up timer1 for a tick every 62.50 microseconds
// for 2000 bits per sec
TCCR0A = 0; [b]<--- Changed TCCR1A to TCCR0A[/b]
TCCR0B = _BV(WGM02) | _BV(CS10); [b]<--- Changed TCCR1B to TCCR0B and WGM12 to WGM02[/b]
// Caution: special procedures for setting 16 bit regs
OCR1A = ocr1a;
// Enable interrupt
TIMSK1 |= _BV(OCIE1A);
TIMSK |= _BV(OCIE1A);
What can I do to resolve this? I also tried to get two attiny85 to communicate with each other (both at 16MHz) and it worked fine (but slower than the Mega2560).