MCP7940N _RTC without Library

Dear all

I would like to Know what is read and write procedure to Get RTC data without library function.

weather its proper
I2c write

i2c_start() ; // start I2C communication: SDA goes down while SCL remains high
i2c_wr(ADDR_RTCC_WRITE); // send the RTCC's address for write = 0xde
i2c_wr(rtcc_reg) ; // send the register's address
i2c_wr (time_var) ; // send the data byte
i2c_stop() ; // stop I2C communication: SDA goes high while SCL remains high

I2c Read

i2c_start() ; // start I2C communication: SDA goes down while SCL remains high
i2c_wr(ADDR_RTCC_WRITE); // send the RTCC's address for write = 0xde
i2c_wr(rtcc_reg) ; // send the register's address
i2c_restart() ; // switch to reads
i2c_wr(ADDR_RTCC_READ) ; // send the RTCC's address for read = 0xdf
i2c_rd() ; // read the byte from the RTCC (register's content)
i2c_nack ; // NoACK from MCU to the RTCC (no more bytes to read)
i2c_stop() ; // stop I2C communication: SDA goes high while SCL remains high

Weather I2c function like we use PIC it will work on Arduino IDE.?? is any code example available
without wire library but using normal syntax

example we like using

[b]unsigned short I2C_Read(unsigned short ack)
{
  unsigned short incoming;
  I2C_Hold();
  RCEN = 1;

  I2C_Hold();
  incoming = SSPBUF;      //get the data saved in SSPBUF

  I2C_Hold();
  ACKDT = (ack)?0:1;    //check if ack bit received 
  ACKEN = 1;          //pg 85/234

  return incoming;
}[/b]


void I2C_Write(unsigned data)
{
  I2C_Hold(); //Hold the program is I2C is busy
  SSPBUF = data;         //pg82/234
}

void I2C_Hold()
{
    while (   (SSPCON2 & 0b00011111)    ||    (SSPSTAT & 0b00000100)   ) ; //check the this on registers to make sure the IIC is not in progress
}

Something along these lines should work for an MCP7940N:

#define RTC_ADDRESS 0x6F

Wire.beginTransmission(RTC_ADDRESS);
Wire.write(0);
Wire.endTransmission();

Wire.requestFrom(RTC_ADDRESS, 7);
if (Wire.available() == 7) {
  for(i=0;i<7;i++) {
    rtcRegister(i) = Wire.read();
  }
}

Basically, you are telling the RTC to set its internal address pointer to 0 - which is the address of the RTCSEC register. You then request 7 bytes from the RTC. The MCP7940N will auto increment its internal address pointer after each byte. You will then end up with the values of the RTCSEC, RTCMIN, RTCHOUR, RTCWKDAY, RTCDATE, RTCMTH and RTCYEAR registers being read out over the I2C bus.

Note that the actual reading of the registers is done with the Wire.requestFrom() call. The Wire.read() calls are accessing the locally cached I2C data that has just been received.

I would like to Know people have wire.cpp library . I would like to know how to use

function Directly here.

For example when we say I2c_Start() in PIC controller. In case of arduino how i can use function

void I2c_start()
{
SSP1CON2bits.SEN=1;

}

I'm not familiar with PIC micros. Hopefully somebody else will jump in and help you out.

That expression refers to a specific bit on hardware register on a PIC. Probabky there is some equivalent on every microprocessor with a hardware I2C capability.

Spend some time with the data sheets for the two processors you are trying to translate between.

Spend some time working through the code of the Arduino library.

If you know what you're doing, you'll know what you're doing. Otherwise you won't, and you should just use the library.

Seriously.

a7