This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

BQ32000: BQ32000

Part Number: BQ32000

we are using external RTC BQ32000 for PIC32MM0256GPM064 microcontroller.we faced issues utilizing BQ32000.

we tried to updated the time in RTC.it was successfull but the time is not incremented .

we changed the rtc.it was not work.

kindly suggest the solutions for RTC issue


#include <xc.h>
#include <stdio.h>
#include <stdlib.h>


#define I2Cwrite     0xD0
#define I2CRead     0xD1


void I2C_wait_for_idle(void)
{

while(I2C3CON & 0x1F);
while(I2C3STATbits.TRSTAT);
}


void I2C_start()
{
I2C_wait_for_idle();
I2C3CONbits.SEN = 1;
while (I2C3CONbits.SEN == 1);
}

void I2C_stop()
{
I2C_wait_for_idle();
I2C3CONbits.PEN = 1;
}

void I2C_restart()
{
I2C_wait_for_idle();
I2C3CONbits.RSEN = 1;
while (I2C3CONbits.RSEN == 1);
}
void I2C_ack(void)
{
I2C_wait_for_idle();
I2C3CONbits.ACKDT = 0;
I2C3CONbits.ACKEN = 1;
while(I2C3CONbits.ACKEN);
}

void I2C_nack(void)
{
I2C_wait_for_idle();
I2C3CONbits.ACKDT = 1;
I2C3CONbits.ACKEN = 1;
while(I2C3CONbits.ACKEN);
}

void I2c_write(unsigned char address, char wait_ack)
{
I2C3TRN = address | 0;
while (I2C3STATbits.TBF == 1);
I2C_wait_for_idle();
if (wait_ack) while (I2C1STATbits.ACKSTAT == 1);
}

void I2c_read(unsigned char *value, char ack_nack)
{
I2C3CONbits.RCEN = 1;
while (I2C3CONbits.RCEN);
while (!I2C3STATbits.RBF);
*value = I2C3RCV;

if (!ack_nack)
I2C_ack();
else
I2C_nack();
}

void I2C_Initialize()
{
LATC = 0x00;
ANSELBbits.ANSB13 = 0;
TRISBbits.TRISB13 = 1;
TRISBbits.TRISB7 = 1;
I2C3CONbits.ON = 1;
I2C3CONbits.DISSLW = 1;
I2C3BRG = 7;
I2C3STAT = 0x0;
}

void BQ32000_write(unsigned char reg_address, unsigned char value)
{
I2C_start();
I2c_write(I2Cwrite , 1);
I2c_write(reg_address,1);
I2c_write(value,1);
I2C_stop();
}
void BQ32000_read(unsigned char reg_address, unsigned char *value)
{
I2C_start();
I2c_write(I2Cwrite , 1);
I2c_write(reg_address,1);
I2C_restart();
I2c_write( I2CRead ,1);
I2c_read(value, 1);
I2C_stop();
}

void rtc_read()
{

BQ32000_read(0x00, &sec);
BQ32000_read(0x01, &min);
BQ32000_read(0x02, &hours);
BQ32000_read(0x03, &date);
BQ32000_read(0x04, &day);
BQ32000_read(0x05, &month);
BQ32000_read(0x06, &years);


}

void rtc_write()
{

BQ32000_write(0x00, 0x00);
BQ32000_write(0x01, 0x00);
BQ32000_write(0x02, 0x00);
BQ32000_write(0x03, 0x05);
BQ32000_write(0x04, 0x06);
BQ32000_write(0x05, 0x05);
BQ32000_write(0x06, 0x23);


}