Workflow

  1. 1.
    Enable the AST module:
    ast_enable(AST); 
    
  2. 2.
    Initialize the AST to counter mode:
    * struct ast_config ast_conf;
    * ast_conf.mode = AST_COUNTER_MODE;
    * ast_conf.osc_type = AST_OSC_32KHZ;
    * ast_conf.psel = AST_PSEL_32KHZ_1HZ;
    * ast_conf.counter = 0;
    * ast_set_config(AST, &ast_conf);
    * 
    
  3. 3.
    Or initialize the AST to calendar mode:
    * struct ast_calendar calendar;
    * struct ast_config ast_conf;
    * calendar.FIELD.sec = 0;
    * calendar.FIELD.min = 15;
    * calendar.FIELD.hour = 12;
    * calendar.FIELD.day = 20;
    * calendar.FIELD.month = 9;
    * calendar.FIELD.year = 12;
    * struct ast_config ast_conf;
    * ast_conf.mode = AST_CALENDAR_MODE;
    * ast_conf.osc_type = AST_OSC_32KHZ;
    * ast_conf.psel = AST_PSEL_32KHZ_1HZ;
    * ast_conf.calendar = calendar;
    * ast_set_config(AST, &ast_conf) 
    
    Note:

    We need to set the clock after prescaler to 1Hz.