Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] how to write and read to RTC

Status
Not open for further replies.

akshaybhavsar

Full Member level 2
Joined
May 5, 2016
Messages
135
Helped
2
Reputation
4
Reaction score
2
Trophy points
18
Activity points
898
I am getting problem with RTC mcp79410.I am new with Rtc programming.
how to set time and date in RTC.whether it is to be written in eeprom or sram?.how to read date and time?:oops::thumbsdown:
 

Code:
unsigned char data[10];
    int datasize;
    int index=0;
    data[0]=0xDE;
    data[1]=0x00;
    data[2]=0x20;
    data[3]=0x21;
    data[4]=0x80;
//    data[5]=0x81;
//    data[6]=0x27;
//    data[7]=0x01;
//    data[8]=0x15;
   datasize=9;
    
    StartI2C1();//Send the Start Bit
    IdleI2C1();//Wait to complete
    while(datasize)
    {
        k=MasterWriteI2C1(data[index]);
    IdleI2C1();//Wait to complete
    datasize--;
    index++;
    
    if( I2C1STATbits.ACKSTAT )
break;
        
    }
  // k= MasterputsI2C1(data);
   
    
    StopI2C1();//Send the Stop condition
IdleI2C1();//Wait to complete

StartI2C1();//Send the Start Bit
IdleI2C1();//Wait to complete
       
k=MasterWriteI2C1(0xDE);
    IdleI2C1();//Wait to complete

 k=MasterWriteI2C1(0x00);
     IdleI2C1();//Wait to complete
     

     RestartI2C1();//Send the Stop condition
IdleI2C1();//Wait to complete
     
k=MasterWriteI2C1(0xDF);
IdleI2C1();//Wait to complete



getvalue=MasterReadI2C1();
        
 StopI2C1();//Send the Stop condition
IdleI2C1();//Wait to complete
 
Last edited by a moderator:

Hi,

what is AN1414?

What about doing a search by yourself?
--> Google: first hit!
--> microchip search: first hit!

Klaus
 

I havent got it for PIC 32mx...there is mo application note for RTC with pic32mx
 

If you are using an external RTC chip then the documentation for that chip will tell you how you need to communicate with it. All you need to know from the PIC32MX's point of view is how to send and receive via I2C and there are *many* examples for that.
AN1414 uses a PIC16F1937 but there is very little in the document that is specific to that chip. Virtually everything in there relates to how to talk to the RTC chip via I2C.
If you are looking for something to blindly copy without any understanding of what you are doing then you will not get very far. If you apply the principles and the bulk of the information in the app note (plus the data sheet) then you will get a satisfactory outcome very easily.
Susan
 
Thank u so much...finally i got it working.I forgot to enable oscillator bit of RTC in SFR.
 

Thank u so much...finally i got it working.I forgot to enable oscillator bit of RTC in SFR.

Good to know. Basically IIC is a protocol for communication and two devices that support the protocol can talk to each other. It is basically a serial communication, like RS232 or USB but you need to understand that the protocols are different. Once both the devices support the protocol, they are in principle able to communicate. The reason that I mention "in principle" is that some basic software drivers must be installed and these drivers basically provide a set of callable routines or functions that hide the hardware layer. Once your program is compiled and the executable is loaded in memory, these differences are no more significant.

In your post #4, you have submitted code that contains the drivers for the I2C (or IIC) protocol layers. If you concentrate hard, you will notice that these calls are available in the code project itself suggests that the PIC you are using is very likely IIC compatible.
 
we can connect no of devices to I2C .how to decide addresses for each device.
 

Thanxxx.it means we can't set our own address value in firmware
 

Hi,

if you want to send a letter to your firend .. for sure you may write "any" address on the letter.
But only the letter with the correct address will arrive at your friend.

Klaus
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top