Demo the function of RTC module AM1805

Dependencies:   mbed-dev

Fork of I2C_HelloWorld_Mbed by mbed official

Files at this revision

API Documentation at this revision

Comitter:
marcusC
Date:
Thu Dec 24 05:15:42 2015 +0000
Parent:
1:c45df8c46fa8
Commit message:
Remove the redundant log

Changed in this revision

AM1805.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c45df8c46fa8 -r 16b8f527b5c7 AM1805.cpp
--- a/AM1805.cpp	Thu Dec 24 03:30:20 2015 +0000
+++ b/AM1805.cpp	Thu Dec 24 05:15:42 2015 +0000
@@ -24,10 +24,10 @@
 /* Register Value */
 #define AM1805_VALUE_ID0 0x18
 
-#define AM1805_DEBUG
+#define AM1805_DEBUG 0
 
 I2C i2c(I2C_SDA, I2C_SCL);
-#ifdef AM1805_DEBUG
+#if AM1805_DEBUG
 Serial pc(p13,p14);
 #endif
 
@@ -70,7 +70,7 @@
 {
     char who_am_i[1];
     am1805_register_read(AM1805_REG_ID0, &who_am_i[0], 1);    
-#ifdef AM1805_DEBUG    
+#if AM1805_DEBUG    
     pc.printf("ID:%x\r\n",who_am_i[0]);
 #endif    
     if (who_am_i[0] != AM1805_VALUE_ID0) 
@@ -126,7 +126,7 @@
             setreg(AM1805_REG_INTMASK,0x02);            // Set EX2E       
             break;
         default:
-#ifdef AM1805_DEBUG    
+#if AM1805_DEBUG    
             pc.printf("Wrong Input Interrupt Index\r\n");
 #endif         
             break;        
@@ -145,7 +145,7 @@
     am1805_register_write(AM1805_REG_EXTADDR_REG, xadd);    // Load the XADDR register
     reg_ram = (address & 0x3F) | 0x40;                      // Read the data
     am1805_register_read(reg_ram, &temp, 1);
-#ifdef AM1805_DEBUG  
+#if AM1805_DEBUG  
     pc.printf("Read from addr:%x Data:%x\r\n",address,temp);
 #endif    
     return (uint8_t)temp;                
@@ -272,7 +272,7 @@
     time_regs->year = temp_buff[6];
     time_regs->weekday = temp_buff[7];
 
-#ifdef AM1805_DEBUG 
+#if AM1805_DEBUG 
     pc.printf("hundredth:%x\r\n",time_regs->hundredth);
     pc.printf("second:%x\r\n",time_regs->second);
     pc.printf("minute:%x\r\n",time_regs->minute);
@@ -309,35 +309,16 @@
     clrreg(AM1805_REG_TIM_CTRL, 0x1C);      // Clear the RPT field
     clrreg(AM1805_REG_INTMASK, 0x64);       // Clear the AIE bit and IM field
     clrreg(AM1805_REG_STATUS, 0x04);        // Clear the ALM flag
-//////////////////////////////
-clrreg(AM1805_REG_CTRL1, 0x10);
-/////////////////////////////
 
     if (pin == PIN_FOUT_nIRQ)
     {
         /* Interrupt on FOUT/nIRQ */
-        am1805_register_read(AM1805_REG_CTRL2, &temp, 1);   // Get the Control2 Register
-/////////////////
-//pc.printf("111111111:AM1805_REG_CTRL2:%x\r\n",temp);
-setreg(AM1805_REG_CTRL2, 0x03);    // Set OUT1S to 3
-/////////////////        
+        am1805_register_read(AM1805_REG_CTRL2, &temp, 1);   // Get the Control2 Register       
         temp = (temp & 0x03);               // Extract the OUT1S field        
         if (temp != 0)                      // Not already selecting nIRQ
         {
-            setreg(AM1805_REG_CTRL2, 0x03);    // Set OUT1S to 3
-///////////////////
-//pc.printf("2222222:AM1805_REG_CTRL2:%x\r\n",temp);
-///////////////////            
-        }
-///////////////
-char bufff = 0;
-am1805_register_read(AM1805_REG_CTRL1, &bufff, 1);   // Get the Control2 Register
-//pc.printf("99999:AM1805_REG_CTRL1:%x\r\n",bufff);
-am1805_register_read(AM1805_REG_CTRL2, &bufff, 1);   // Get the Control2 Register
-//pc.printf("33333:AM1805_REG_CTRL2:%x\r\n",bufff);
-am1805_register_read(AM1805_REG_STATUS, &bufff, 1);   // Get the Control2 Register
-//pc.printf("55555:AM1805_REG_STATUS:%x\r\n",bufff);
-///////////////        
+            setreg(AM1805_REG_CTRL2, 0x03);    // Set OUT1S to 3           
+        }        
     }
     if (pin == PIN_PSW_nIRQ2)
     {
@@ -367,25 +348,10 @@
     {
         temp = (repeat << 2);                       // Set the RPT field to the value of repeat
         setreg(AM1805_REG_TIM_CTRL, temp);          // Was previously cleared
-        //setreg(AM1805_REG_INTMASK, (intmode << 5)); // Set the alarm interrupt mode
+        setreg(AM1805_REG_INTMASK, (intmode << 5)); // Set the alarm interrupt mode
         setreg(AM1805_REG_INTMASK, 0x60); // Set the alarm interrupt mode
         am1805_burst_write(temp_buff, 8);           // Execute the burst write
-        setreg(AM1805_REG_INTMASK, 0x04);           // Set the AIE bit
-///////////////////
-char bufff = 0;
-am1805_register_read(AM1805_REG_INTMASK, &bufff, 1);   // Get the Control2 Register
-//pc.printf("6666:AM1805_REG_INTMASK:%x\r\n",bufff);
-am1805_register_read(AM1805_REG_TIM_CTRL, &bufff, 1);   // Get the Control2 Register
-//pc.printf("7777:AM1805_REG_TIM_CTRL:%x\r\n",bufff);
-am1805_register_read(AM1805_REG_STATUS, &bufff, 1);   // Get the Control2 Register
-//pc.printf("8888:AM1805_REG_STATUS:%x\r\n",bufff);
-/* Read the counters. */
-char buff[7];
-am1805_register_read(AM1805_REG_ALM_HUN, buff, 7);
-uint8_t i;
-for(i = 0; i < 7 ;i++){}
-//pc.printf("buff[%d]:%x\r\n",i,buff[i]);
-///////////////         
+        setreg(AM1805_REG_INTMASK, 0x04);           // Set the AIE bit        
     }
     else
         setreg(AM1805_REG_INTMASK, 0x60);           // Set IM field to 0x3 (reset value) to minimize current draw
@@ -580,7 +546,7 @@
     uint8_t slres = 0;
     char temp = 0;
 
-#ifdef AM1805_DEBUG    
+#if AM1805_DEBUG    
     am1805_register_read(AM1805_REG_CTRL2, &temp, 1);       // Get SLST bit (temp & 0x08)
     
     if ( ( temp & 0x08 ) == 0)
@@ -614,7 +580,7 @@
     temp = timeout | (slres << 6) | 0x80;                   // Assemble SLEEP register value
     am1805_register_write(AM1805_REG_SLEEPCTRL, temp);      // Write to the register    
 
-#ifdef AM1805_DEBUG
+#if AM1805_DEBUG
     /* Determine if SLEEP was accepted */
     am1805_register_read(AM1805_REG_CTRL2, &temp, 1);       // Get SLP bit (temp & 0x80)