attiny, low pwr и virtualwire

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good afternoon
I'm trying to implement the following task on attiny:
There are attiny85 and rf433. It is necessary to send the word "test" from rf433 to the receiver and then go to sleep for 8 seconds, then wake up again, and so on in a circle. If i use a normal led instead of rf433 and a virtualwire library to track the performance, as if everything seems to work, consumption in sleep mode is small enough to make the chip work without changing the battery, for example:

#include <avr/sleep.h>
#include <avr/wdt.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
int Led = 2;
volatile boolean f_wdt = 1;

void setup(){
pinMode(Led,OUTPUT);
}

void loop(){
if (f_wdt==1) {
f_wdt=0;

digitalWrite(Led,HIGH);
delay(300);
digitalWrite(Led,LOW);
pinMode(Led,INPUT);
deep_sleep();
pinMode(Led,OUTPUT);
}}
void deep_sleep() {
int ii = 9;
  byte bpb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;

MCUSR &= ~(1<<WDRF);
// start timed sequence
WDTCR |= (1<<WDCE) | (1<<WDE);
// set new watchdog timeout value
WDTCR = bb;
WDTCR |= _BV(WDIE);
cbi(ADCSRA,ADEN);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_mode();
sleep_disable();
sbi(ADCSRA,ADEN);
}

// Watchdog Interrupt Service / is executed when watchdog timed out
ISR(WDT_vect) {
f_wdt=1;  // set global flag
}

But as soon as I connect the virtualwire library, configure the sensor and try to send something, wdt stops working, the data through the module is also not transmitted.
Example:

#include <VirtualWire.h>
..
void setup(){
pinMode(pinLed,OUTPUT);
   vw_set_ptt_inverted(true);
   vw_set_tx_pin(1);
   vw_setup(2000);
}
...
void loop(){
if (f_wdt==1) {  // wait for timed out watchdog / flag is set when a watchdog timeout occurs
f_wdt=0; // reset flag
char msg[36];
printf(msg, "test");
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
digitalWrite(pinLed,HIGH);
delay(300);
digitalWrite(pinLed,LOW);
pinMode(pinLed,INPUT);
deep_sleep(2);
pinMode(pinLed,OUTPUT);
}}
...

I plug everything into a straight line and I do not use , resistors, capacitors or quartz for a test on a layout . If i try to pass something without wdt then virtualwire with the above configuration (the second example) works without problems.
What am I doing wrong? hheeeelp me

i use library 

http://www.airspayce.com/mikem/arduino/VirtualWire/VirtualWire-1.20.zip