CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

IS1208 RTC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
haseeb



Joined: 27 Apr 2011
Posts: 19

View user's profile Send private message

IS1208 RTC
PostPosted: Mon Sep 26, 2011 7:54 am     Reply with quote

Hello

I'm using PIC18F2620 internal OSC @ 4MHz and I'm using the
ISL1208 RTC with the PIC.

Simple objective, is to set RTC alarm INT to 1minute repetitive cycle
so that the PIC wakes up via its INT0 after every minute and prints out on
hyper terminal. Sadly nothing seems to be happening. I know my PIC
board is fine cause my flashing LED program works fine on this board and
I also previously tried the DS1307 RTC as well on same board and it
worked. The reason I'm using ISL1208 is because of its alarm feature.
The ISL1208 operates at 400kHz where as the DS1307 operates
at 100kHz. Could this be the problem? I'm using CCS compiler and
can not seem to change that setting...or do i even need to?

Please can someone help me to achieve this simple program objective.

Below is my test code.

Thanks
Haseeb

Code:

#include <18F2620.h>
#include <stdio.h> 

#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,NOPUT, NOPBADEN 
// Set Speed to 4Mhz
#use delay(clock=4000000)
// RS232 to Modem
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_B5, STREAM=Modem)
// RTS232 to User Port
#use rs232(baud=9600, xmit=PIN_B4, rcv=PIN_C7, STREAM=User)
// Configure I2C as Master
#use i2c(master, sda=PIN_C4 , scl=PIN_C3) 

char clock_sleeping = 1, //flag to tell us that we have woken up from sleeping when the clock is INT (0 = wakeup / 1 = sleep)

    SC; //dumping the contents of the SC register from ISL1208

//Defining ISRs....

#int_ext
void EXT_ISR (void)
{   
   //we have woken up from sleep
   clock_sleeping = 0;      
}


void main(void)
{
   delay_ms(100); //startup delay
   
   EXT_INT_EDGE(0,H_TO_L);         // Int0 Edge Trigger - high to low transition
   EXT_INT_EDGE(1,H_TO_L);         // Int1 Edge Trigger - high to low transition
   enable_interrupts(INT_EXT);      // Enable int0
   enable_interrupts(INT_EXT1);   // Enable int1    
   enable_interrupts(GLOBAL);      // Enable all interupts

   //Reseting all RTC registers to 'ZERO'.....

     i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x00);          // Reset Second (SC)
    i2c_write(0x00);         // data byte ZERO
    i2c_stop();

   delay_ms(100); //startup delay

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x01);          // Reset Minute (MN)
    i2c_write(0x00);         // data byte ZERO
    i2c_stop();

   delay_ms(100); //startup delay

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x02);          // Reset Hour (HR)
    i2c_write(0x00);         // data byte ZERO
    i2c_stop();

   delay_ms(100); //startup delay

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x03);          // Reset date (DT)
    i2c_write(0x00);         // data byte ZERO
    i2c_stop();
   
   delay_ms(100); //startup delay

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x04);          // Reset Month (MO)
    i2c_write(0x00);         // data byte ZERO
    i2c_stop();

   delay_ms(100); //startup delay

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x05);          // Reset Year (YR)
    i2c_write(0x00);         // data byte ZERO
    i2c_stop();
   
   delay_ms(100); //startup delay

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x06);          // Day of the Week (DW)
    i2c_write(0x00);         // data byte ZERO
    i2c_stop();

   delay_ms(100); //startup delay

   //Configuring the Interrupt Control Register (IR)

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x08);          // Address of (IR) register
    i2c_write(0xC0);         // data byte (IM = 1, ALME = 1, LPMODE = 0, FOBATB = 0, FO3 = 0, FO2 = 0, FO1 = 0, FO0 = 0)
    i2c_stop();               

   delay_ms(100); //startup delay

   //Configuring the Alarm Registers...

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x0C);          // Second register (SCA)
    i2c_write(0xB0);         // Seconds set to 30, enabled
    i2c_stop();                                    delay_ms(100); //startup delay

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x0D);          // Minute register (MNA)
    i2c_write(0x00);         // Minutes disabled
    i2c_stop();   
   
   delay_ms(100); //startup delay      

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x0E);          // Hour register (HRA)
    i2c_write(0x00);         // Hours disabled
    i2c_stop();   

   delay_ms(100); //startup delay      

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x0F);          // Date register (DTA)
    i2c_write(0x00);         // Date disabled
    i2c_stop();   

   delay_ms(100); //startup delay      

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x10);          // Month register (MOA)
    i2c_write(0x00);         // Month disabled
    i2c_stop();   

   delay_ms(100); //startup delay      

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x11);          // Day of the Week register (DWA)
    i2c_write(0x00);         // Day of the Week disabled
    i2c_stop();   

   delay_ms(100); //startup delay

   //Configuring the Status Register (SR)

    i2c_start();
    i2c_write(0xDE);          // address of the ISL1208 (Write Mode)   
    i2c_write(0x07);          // Address of (SR) register
    i2c_write(0x90);         // data byte (ARST = 1, XTOSCB = 0, Reserved = 0, WRTC = 1, Reserved = 0, ALM = 0, BAT = 0, RTCF = 0)
    i2c_stop();               

   delay_ms(100); //startup delay

    while(TRUE)
   {
      sleep(); //goto sleep now...

      delay_ms(100); //When waking up, delay needed to bring the PIC up to working state

      if(clock_sleeping == 0) //did we wake up from clock INT?      
      {         
         //Reading the Status Register (SR) to Reset the Alarm bit - (ALM)
         i2c_start();
         i2c_write(0xDF);       // address of the ISL1208 (Read Mode)   
          SC = i2c_read(0x07);   //dumping the contents of the SC register into a dummy variable
          i2c_stop();      

         fprintf(User,"PIC Woke UP!");   // print to screen
         
         clock_sleeping = 1; //set sleep flag to indicate that we are about to goto sleep again...      
      }            
   }

}

Ttelmah



Joined: 11 Mar 2010
Posts: 19498

View user's profile Send private message

PostPosted: Mon Sep 26, 2011 9:08 am     Reply with quote

Some comments:

1) You enable int_ext1, as well as int_ext, and don't have a handler for this. This _will_ cause the code to crash.
2) You are misunderstanding I2C. I2C, only ever transfers data in one direction at a time. You can't send a value with an I2C_READ. The only thing transmissible with a read instruction is the ACK/NACK bit at the end. The normal way to read a specific register is:
Code:

i2c_start();
i2c_write(device_write_address);
i2c_write(register_address);
i2c_start(); //perform a repeated start, so you can turn the bus around
i2c_write(device_read_address);
i2c_read(ACK/NACK);
i2c_stop();

So you _write_the address number you want, then turn the bus around. Normally you should 'NACK' the last byte you then read (0 in the read command).

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group