Show Posts
Pages: [1] 2 3
1  Using Arduino / Networking, Protocols, and Devices / Re: Problems with DS3234, is damaged? on: August 05, 2013, 05:31:45 am
some help???
2  Using Arduino / Networking, Protocols, and Devices / Problems with DS3234, is damaged? on: August 03, 2013, 12:49:30 pm
Hello,
I've two DS3234 connected to two different Arduinos, I followed this tutorial http://www.l8ter.com/?p=375 one of them works perfectly but the other show me the following in Serial monitor:

Quote
10/10/10     10:10:0
11/11/11     11:11:11
12/12/12     12:12:12
13/13/13     13:13:13
14/14/14     14:14:14
15/15/15     15:15:15
16/16/16     16:16:16
17/17/17     17:17:17
18/18/18     18:18:18
19/19/19     19:19:19
20/0/20     20:20:20
21/1/21     21:21:21
22/2/22     22:22:22
23/3/23     23:23:23
24/4/24     24:24:24
25/5/25     25:25:25
26/6/26     26:26:26
27/7/27     27:27:27
28/8/28     28:28:28
29/9/29     29:29:29
30/10/30     3:30:30
31/11/31     4:31:31
32/12/32     5:32:32
33/13/33     6:33:33
34/14/34     7:34:34
35/15/35     8:35:35
36/16/36     9:36:36
37/17/37     10:37:37
38/18/38     11:38:38
39/19/39     12:39:39
0/0/40     0:40:40
1/1/41     1:41:41
2/2/42     2:42:42
3/3/43     3:43:43
4/4/44     4:44:44
5/5/45     5:45:45
6/6/46     6:46:46

It seems that every second increase all records in one unit, if I only read every 5 seconds they increased 5 units.
Could it be a wiring or soldering problem or is the DS3234 damaged?

Best regards.
3  International / Software / Re: Problema con interrupcion, despertar el arduino y DS3234 on: July 28, 2013, 02:58:08 pm
Conseguido, tiene la ventaja que se puede cambiar facilmente el tiempo que va a estar dormido, economizando así mucho la batería.

Por si a alguien le interesa el código:

Code:
#include <SPI.h>
#include "ds3234.h"
#include "Enerlib.h"

#define BUFF_MAX 256

const int cs = 8;              // chip select pin
uint8_t sleep_period = 5;      // the sleep interval in minutes between 2 consecutive alarms
Energy energy;
int time_interrupt=0;


void set_next_alarm(void)
{
 
    struct ts t;
    unsigned char wakeup_min;

    DS3234_get(cs, &t);

    // calculate the minute when the next alarm will be triggered
    wakeup_min = (t.min / sleep_period + 1) * sleep_period;
    if (wakeup_min > 59) {
        wakeup_min -= 60;
    }

    // flags define what calendar component to be checked against the current time in order
    // to trigger the alarm
    // A2M2 (minutes) (0 to enable, 1 to disable)
    // A2M3 (hour)    (0 to enable, 1 to disable)
    // A2M4 (day)     (0 to enable, 1 to disable)
    // DY/DT          (dayofweek == 1/dayofmonth == 0)
    boolean flags[4] = { 0, 1, 1, 1 };

    // set Alarm2. only the minute is set since we ignore the hour and day component
    DS3234_set_a2(cs, wakeup_min, 0, 0, flags);

    // activate Alarm2
    DS3234_set_creg(cs, DS3234_INTCN | DS3234_A2IE);
   
}

void INT0_ISR(void)
{
  //detach interrupt and set time_interrupt=1
  //interrupt must be attached again
  detachInterrupt(0);
  time_interrupt=1;

}

void setup()
{
    Serial.begin(9600);
    Serial.println("Entering setup");
    pinMode(2, INPUT);
    delay(5000);
    DS3234_init(cs, DS3234_INTCN);
    DS3234_clear_a2f(cs);
    set_next_alarm();
    attachInterrupt(0, INT0_ISR, LOW);
}


void loop()
{
  if(time_interrupt==1){
    Serial.println(" time_interrupt==1");
    time_interrupt=0;
   
    // set next alarm
    set_next_alarm();
    // clear a2 alarm flag and let INT go into hi-z
    DS3234_clear_a2f(cs);
    //Attach interrupt again
    attachInterrupt(0, INT0_ISR, LOW);
    if (energy.WasSleeping())
      {
        Serial.println("  Interrupt and was sleeping");
      }
    else
      {
        /*
        The IRQ happened in awake state.
        This code is for the "normal" ISR.
        */
    Serial.println("  Interrupt and was NOT sleeping");
      }
  }
  Serial.println("Entering loop");
  delay(1000);
  /*
  //For debuf only
  char buff[BUFF_MAX];
  struct ts t;
   
  DS3234_get(cs, &t);
  // display current time
  snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year, t.mon, t.mday, t.hour, t.min, t.sec);
  Serial.println(buff);
  */
  Serial.println("Powering down");
  energy.PowerDown();

}
4  Using Arduino / Programming Questions / Re: DS3234, interrupts and alarms on: July 28, 2013, 02:55:49 pm
Now it works!

I need an alarm that wake up the Arduino every 5 minutes or more.

Code:

Code:
#include <SPI.h>
#include "ds3234.h"
#include "Enerlib.h"

#define BUFF_MAX 256

const int cs = 8;              // chip select pin
uint8_t sleep_period = 5;      // the sleep interval in minutes between 2 consecutive alarms
Energy energy;
int time_interrupt=0;


void set_next_alarm(void)
{
 
    struct ts t;
    unsigned char wakeup_min;

    DS3234_get(cs, &t);

    // calculate the minute when the next alarm will be triggered
    wakeup_min = (t.min / sleep_period + 1) * sleep_period;
    if (wakeup_min > 59) {
        wakeup_min -= 60;
    }

    // flags define what calendar component to be checked against the current time in order
    // to trigger the alarm
    // A2M2 (minutes) (0 to enable, 1 to disable)
    // A2M3 (hour)    (0 to enable, 1 to disable)
    // A2M4 (day)     (0 to enable, 1 to disable)
    // DY/DT          (dayofweek == 1/dayofmonth == 0)
    boolean flags[4] = { 0, 1, 1, 1 };

    // set Alarm2. only the minute is set since we ignore the hour and day component
    DS3234_set_a2(cs, wakeup_min, 0, 0, flags);

    // activate Alarm2
    DS3234_set_creg(cs, DS3234_INTCN | DS3234_A2IE);
   
}

void INT0_ISR(void)
{
  //detach interrupt and set time_interrupt=1
  //interrupt must be attached again
  detachInterrupt(0);
  time_interrupt=1;

}

void setup()
{
    Serial.begin(9600);
    Serial.println("Entering setup");
    pinMode(2, INPUT);
    delay(5000);
    DS3234_init(cs, DS3234_INTCN);
    DS3234_clear_a2f(cs);
    set_next_alarm();
    attachInterrupt(0, INT0_ISR, LOW);
}


void loop()
{
  if(time_interrupt==1){
    Serial.println(" time_interrupt==1");
    time_interrupt=0;
   
    // set next alarm
    set_next_alarm();
    // clear a2 alarm flag and let INT go into hi-z
    DS3234_clear_a2f(cs);
    //Attach interrupt again
    attachInterrupt(0, INT0_ISR, LOW);
    if (energy.WasSleeping())
      {
        Serial.println("  Interrupt and was sleeping");
      }
    else
      {
        /*
        The IRQ happened in awake state.
        This code is for the "normal" ISR.
        */
    Serial.println("  Interrupt and was NOT sleeping");
      }
  }
  Serial.println("Entering loop");
  delay(1000);
  /*
  //For debuf only
  char buff[BUFF_MAX];
  struct ts t;
   
  DS3234_get(cs, &t);
  // display current time
  snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year, t.mon, t.mday, t.hour, t.min, t.sec);
  Serial.println(buff);
  */
  Serial.println("Powering down");
  energy.PowerDown();

}
5  Using Arduino / Programming Questions / Re: DS3234, interrupts and alarms on: July 28, 2013, 02:01:58 pm
Hello Mark,
I rewrite my code, and the problems is the same.

Code:
Code:
#include <SPI.h>
#include "ds3234.h"
#include "Enerlib.h"

#define BUFF_MAX 256

const int cs = 8;              // chip select pin
uint8_t sleep_period = 5;       // the sleep interval in minutes between 2 consecutive alarms
Energy energy;
int time_interrupt=0;

// how often to refresh the info on stdout (ms)
//unsigned long prev = 5000, interval = 5000;


void set_next_alarm(void)
{
 
    struct ts t;
    unsigned char wakeup_min;

    DS3234_get(cs, &t);

    // calculate the minute when the next alarm will be triggered
    wakeup_min = (t.min / sleep_period + 1) * sleep_period;
    if (wakeup_min > 59) {
        wakeup_min -= 60;
    }

    // flags define what calendar component to be checked against the current time in order
    // to trigger the alarm
    // A2M2 (minutes) (0 to enable, 1 to disable)
    // A2M3 (hour)    (0 to enable, 1 to disable)
    // A2M4 (day)     (0 to enable, 1 to disable)
    // DY/DT          (dayofweek == 1/dayofmonth == 0)
    boolean flags[4] = { 0, 1, 1, 1 };

    // set Alarm2. only the minute is set since we ignore the hour and day component
    DS3234_set_a2(cs, wakeup_min, 0, 0, flags);

    // activate Alarm2
    DS3234_set_creg(cs, DS3234_INTCN | DS3234_A2IE);
   
}

void INT0_ISR(void)
{
 
 
  /*
  The WasSleeping function will return true if Arduino
  was sleeping before the IRQ. Subsequent calls to
  WasSleeping will return false until Arduino reenters
  in a low power state. The WasSleeping function should
  only be called in the ISR.
  */
  //detachInterrupt(0);
  time_interrupt=1;

}

void setup()
{
    Serial.begin(9600);
    Serial.println("Entering setup");
    pinMode(2, INPUT);
    delay(5000);
    DS3234_init(cs, DS3234_INTCN);
    DS3234_clear_a2f(cs);
    set_next_alarm();
    attachInterrupt(0, INT0_ISR, LOW);
}


void loop()
{
  if(time_interrupt==1){
    Serial.println("time_interrupt==1");
    time_interrupt=0;
    if (energy.WasSleeping())
      {
        Serial.println("  Interrupt and was sleeping");
      }
    else
      {
        /*
        The IRQ happened in awake state.
        This code is for the "normal" ISR.
        */
    Serial.println("  Interrupt and was NOT sleeping");
      }
  }
  Serial.println("Entering loop");
  delay(1000);
  //Serial.println("Powering down");
  //energy.PowerDown();
 
 
  char buff[BUFF_MAX];
  struct ts t;
   
  DS3234_get(cs, &t);
  // display current time
  snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year, t.mon, t.mday, t.hour, t.min, t.sec);
  Serial.println(buff);

}
6  Using Arduino / Programming Questions / DS3234, interrupts and alarms on: July 28, 2013, 01:13:55 pm
Hello,

I have a DS3234 RTC configured to trigger an alarm every 5 minutes to wake up the Arduino, the problem is that the interrupt on pin 2 appears to freeze completely the Arduino, if  I don't sleep the arduiuno also be blocked  when interrupt is activated, somebody can help me?

The code is:

Code:
#include <SPI.h>
#include "ds3234.h"
#include "Enerlib.h"

#define BUFF_MAX 256

const int cs = 8;              // chip select pin
uint8_t sleep_period = 5;       // the sleep interval in minutes between 2 consecutive alarms
Energy energy;

// how often to refresh the info on stdout (ms)
//unsigned long prev = 5000, interval = 5000;


void set_next_alarm(void)
{
    struct ts t;
    unsigned char wakeup_min;

    DS3234_get(cs, &t);

    // calculate the minute when the next alarm will be triggered
    wakeup_min = (t.min / sleep_period + 1) * sleep_period;
    if (wakeup_min > 59) {
        wakeup_min -= 60;
    }

    // flags define what calendar component to be checked against the current time in order
    // to trigger the alarm
    // A2M2 (minutes) (0 to enable, 1 to disable)
    // A2M3 (hour)    (0 to enable, 1 to disable)
    // A2M4 (day)     (0 to enable, 1 to disable)
    // DY/DT          (dayofweek == 1/dayofmonth == 0)
    boolean flags[4] = { 0, 1, 1, 1 };

    // set Alarm2. only the minute is set since we ignore the hour and day component
    DS3234_set_a2(cs, wakeup_min, 0, 0, flags);

    // activate Alarm2
    DS3234_set_creg(cs, DS3234_INTCN | DS3234_A2IE);
}

void INT0_ISR(void)
{
  /*
  The WasSleeping function will return true if Arduino
  was sleeping before the IRQ. Subsequent calls to
  WasSleeping will return false until Arduino reenters
  in a low power state. The WasSleeping function should
  only be called in the ISR.
  */
  detachInterrupt(0);
  /*
  set_next_alarm();
  // clear a2 alarm flag and let INT go into hi-z
  DS3234_clear_a2f(cs);
  */
  Serial.println(" Entering interrupt 0");
  if (energy.WasSleeping())
  {
    /*
    Arduino was waked up by IRQ.
   
    If you shut down external peripherals before sleeping, you
    can reinitialize them here. Look on ATMega's datasheet for
    hardware limitations in the ISR when microcontroller just
    leave any low power state.
    */
    Serial.println("  Interrupt and was sleeping");
  }
  else
  {
    /*
    The IRQ happened in awake state.
   
    This code is for the "normal" ISR.
    */
    Serial.println("  Interrupt and was NOT sleeping");
  }
  Serial.println(" Exiting interrupt 0");
}

void setup()
{
    Serial.begin(9600);
    Serial.println("Entering setup");
    pinMode(2, INPUT);
    delay(5000);
    DS3234_init(cs, DS3234_INTCN);
    DS3234_clear_a2f(cs);
    set_next_alarm();
    attachInterrupt(0, INT0_ISR, LOW);
}

void loop()
{
  Serial.println("Entering loop");
  delay(5000);
  Serial.println("Powering down");
  energy.PowerDown();
 
  /*
  char buff[BUFF_MAX];
  struct ts t;
   
  DS3234_get(cs, &t);
  // display current time
  snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year, t.mon, t.mday, t.hour, t.min, t.sec);
  Serial.println(buff);
  */
 
}

A lot of thanks
7  International / Software / Problema con interrupcion, despertar el arduino y DS3234 on: July 28, 2013, 01:10:55 pm
Buenos días,

Tengo un RTC DS3234 configurado para hacer saltar una alarma cada 5 minutos y que despierte el arduino, el problema es que la interrupcion en el pin 2 parece que bloquea totalmente el arduino, de hecho si no lo duermo se bloquea totalmente cuando se activa,alguien puede ayudarme?

El código es:

Code:
// during an alarm the INT pin of the RTC is pulled low

#include <SPI.h>
#include "ds3234.h"
#include "Enerlib.h"

#define BUFF_MAX 256

const int cs = 8;              // chip select pin
uint8_t sleep_period = 5;       // the sleep interval in minutes between 2 consecutive alarms
Energy energy;

// how often to refresh the info on stdout (ms)
//unsigned long prev = 5000, interval = 5000;


void set_next_alarm(void)
{
    struct ts t;
    unsigned char wakeup_min;

    DS3234_get(cs, &t);

    // calculate the minute when the next alarm will be triggered
    wakeup_min = (t.min / sleep_period + 1) * sleep_period;
    if (wakeup_min > 59) {
        wakeup_min -= 60;
    }

    // flags define what calendar component to be checked against the current time in order
    // to trigger the alarm
    // A2M2 (minutes) (0 to enable, 1 to disable)
    // A2M3 (hour)    (0 to enable, 1 to disable)
    // A2M4 (day)     (0 to enable, 1 to disable)
    // DY/DT          (dayofweek == 1/dayofmonth == 0)
    boolean flags[4] = { 0, 1, 1, 1 };

    // set Alarm2. only the minute is set since we ignore the hour and day component
    DS3234_set_a2(cs, wakeup_min, 0, 0, flags);

    // activate Alarm2
    DS3234_set_creg(cs, DS3234_INTCN | DS3234_A2IE);
}

void INT0_ISR(void)
{
  /*
  The WasSleeping function will return true if Arduino
  was sleeping before the IRQ. Subsequent calls to
  WasSleeping will return false until Arduino reenters
  in a low power state. The WasSleeping function should
  only be called in the ISR.
  */
  detachInterrupt(0);
  /*
  set_next_alarm();
  // clear a2 alarm flag and let INT go into hi-z
  DS3234_clear_a2f(cs);
  */
  Serial.println(" Entering interrupt 0");
  if (energy.WasSleeping())
  {
    /*
    Arduino was waked up by IRQ.
   
    If you shut down external peripherals before sleeping, you
    can reinitialize them here. Look on ATMega's datasheet for
    hardware limitations in the ISR when microcontroller just
    leave any low power state.
    */
    Serial.println("  Interrupt and was sleeping");
  }
  else
  {
    /*
    The IRQ happened in awake state.
   
    This code is for the "normal" ISR.
    */
    Serial.println("  Interrupt and was NOT sleeping");
  }
  Serial.println(" Exiting interrupt 0");
}

void setup()
{
    Serial.begin(9600);
    Serial.println("Entering setup");
    pinMode(2, INPUT);
    delay(5000);
    DS3234_init(cs, DS3234_INTCN);
    DS3234_clear_a2f(cs);
    set_next_alarm();
    attachInterrupt(0, INT0_ISR, LOW);
}

void loop()
{
  Serial.println("Entering loop");
  delay(5000);
  Serial.println("Powering down");
  energy.PowerDown();
 
  /*
  char buff[BUFF_MAX];
  struct ts t;
   
  DS3234_get(cs, &t);
  // display current time
  snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year, t.mon, t.mday, t.hour, t.min, t.sec);
  Serial.println(buff);
  */
 
}


Un saludo.
8  Using Arduino / Microcontrollers / Re: atmega328p running at 8mhz with external xtal and serial communication on: March 31, 2013, 12:49:42 pm
Hello, a lot of thanks! with .1ufd cap wired in series between the reset pin and the ftdi DTR works well!!!!
9  Using Arduino / Microcontrollers / Re: atmega328p running at 8mhz with external xtal and serial communication on: March 28, 2013, 08:47:52 am
Quote
To check out the serial side of things, try programming the example sketch "ASCIItable" under File->Examples-> 4. Communication in the IDE into the 328 using the ISP.

Unplug the programmer and plug in the dfrobot and hook it up to the arduino.  Open up the monitor and set the baud rate to 9600. Reboot the Arduino and see if the ASCII table shows up. It only runs once per boot so you have to have the monitor up and running when it boots or you will miss it.

I burn this example using the ISP and works well.

Now, I don't know why, i can burn the bootloader, upload once a program using the dfrobot FTDI (I tried uploading the ASCIItable example) but I can not upload more sketches with FTDI, arduino IDE give me the following error:

Code:
avrdude: stk500_recv(): programmer is not responding

Quote
How have you  got the reset pin wired on the Arduino? Is it on a breadboard?

I'm using a custom circuit in a pcb board. the reset pin is wired to VCC through a resistor.
10  Using Arduino / Microcontrollers / Re: atmega328p running at 8mhz with external xtal and serial communication on: March 28, 2013, 05:18:00 am
Hi xload,

When you plug your dfrobot ftdi into your PC, does it show up as a com port under the Tools-> Serial Port in the IDE?
If so, is it selected?


Yes, it is show as /dev/ttyUSB0 and is selected ins the IDE
11  Using Arduino / Microcontrollers / Re: atmega328p running at 8mhz with external xtal and serial communication on: March 28, 2013, 04:47:28 am
Hello lemming, I burn the "LilyPad Arduino w/ ATmega328" bootloader using arduino IDE and tried to load my sketch using usb/serial cable (dfrobot ftdi) but it reply:

Code:
avrdude: stk500_getsync(): not in sync: resp=0x30

smiley-sad
12  Using Arduino / Microcontrollers / atmega328p running at 8mhz with external xtal and serial communication on: March 27, 2013, 08:20:41 pm
Hello, I've an atmega328p running at 8mhz with external xtal and I need serial communication, first I tried to burn the Arduino bootloader with:

Code:
avrdude -c usbtiny -p atmega328p -e -u -U lock:w:0x3f:m -U efuse:w:0x05:m -U hfuse:w:0xda:m -U lfuse:w:0xff:m
avrdude -c usbtiny -p atmega328p usb -U flash:w:ATmegaBOOT_168_atmega328_pro_8MHz.hex -U lock:w:0x0f:m

But after this I can not upload new programs using Arduino IDE

I also tried uploading blink programs by ISP and works well at correct frequency, I used the followind command:
Code:
avrdude -V -F -c usbtiny -p m328p usb -U flash:w:main.hex
The problems seems to be in the baud rate,I uploaded que following code:

Code:
void setup() {               
Serial.begin(9600);   
}

void loop() {
  Serial.println("hola mundo");
  delay(2000);
}

And I obtained trash on my serial console each 2 seconds.

It seems that the problem is in the baud rate, but I can not understand how to fix it.

Somebody can help me?

Best regards.
13  Using Arduino / Programming Questions / Re: Energy saving question and RTC DS3234 Alarms on: February 03, 2013, 06:56:02 am
Doesn't most RTc have a little bit of NVRAM too?

1) Set alarm_count variable, initialize to 1 and record value in RTc NVRAM
2) Set RTC alarm to 1 minute and trigger an ISR
3) Put to sleep
4) A minute later the alarm triggers your ISR
5) Get the saved value from RTC NVRAM
6) Check alarm_count
7) If alarm_count isn't yet 10 then increment by one, save the value, re-set 1 min alarm and go back to sleep
smiley-cool if alarm_count is 10 then execute your action, rest to 1, save the value, set 1 min alarm and go back to sleep
9) Loop through the wake-up, check, set alarm continuously.

Change a defined value of say alarm_timer and use this for your comparison and you could easily alter the duration from 1 minute to any multiple; 1,5,10,15,28,30,60 etc etf

The time taken to wake up and check the count will be negligible and not have a significant effect if your code is otherwise low load, with the uC otherwise idle in between each action execution.

Hello tack, also is a good idea, I will do this if there is not a better solution.
14  Using Arduino / Programming Questions / Re: Energy saving question and RTC DS3234 Alarms on: February 03, 2013, 06:11:38 am
That info Is on the same page - http://www.gammon.com.au/forum/?id=11497 - search for "Waking from sleep with a timer"

Hello robtillaart, I understand that in the example the arduino is waking up each 8 seconds, the maximum that you can set up a watchdog, but I need wake up each 10 or 15 minutes, how can I do this?
15  Using Arduino / Programming Questions / Re: Energy saving question and RTC DS3234 Alarms on: February 02, 2013, 02:46:05 pm
Some sleep modes keep the timers active,
These timers can be programmed to trigger an ISR.
This ISR can wake the system when appropriate


Hello robtillaart, do you have an example? I don't found it.
Pages: [1] 2 3