Part Number: MSP-EXP430G2
Hello,
I am working with MSP-EXP430G2 evm and my controller is MSP430G2553.i interfaced PCA8565 RTC using i2c protocol.for your reference below i given is my code for this rtc.please try to solve my below query:
1) when i run this code in oscilloscope i am not getting CLK waveform instead i am getting DC voltage at SCL pin.
2) when i run this code then code stuck in function rtc_write_reg(in my code i have highlighted with red colour the line where my code getting stuck).
//=======================================================================================
#include <msp430.h>
#include <stdint.h>
#define RTC_ADDRESS 0xA2
#define I2C_READ 1
#define I2C_WRITE 0
//----------RTC PCA8565 Macros-------------------
#define CONTROL_1 0x00
#define CONTROL_2 0x01
#define SECONDS 0x02
#define MINUTES 0x03
#define HOURS 0x04
#define DAYS 0x05
#define WEEKDAYS 0x06
#define MONTHS_CENTURY 0x07
#define YEARS 0x08
#define CLKUT_CONTROL 0x0D
#define TIMER_CONTROL 0x0E
#define TIMER 0x0F
void i2c_start(void)
{
UCB0CTL1 = UCTR + UCTXSTT; // I2C TX, start condition
while(UCB0CTL1 & UCTXSTT); // Ensure start condition got sent
}
void i2c_write_byte(uint8_t data)
{
UCB0TXBUF = data; // Load TX buffer
while(UCB0CTL1 & UCTXSTT); // wait for Ack from slave
}
void i2c_stop(void)
{
UCB0CTL1 |= UCTXSTP; // I2C stop condition after 1st TX
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
}
void i2c_repeated_start(void)
{
UCB0CTL1 = ~UCTR + UCTXSTT; // I2C RX, start condition
while(UCB0CTL1 & UCTXSTT); // Ensure repeated start condition got sent
}
uint8_t i2c_read_byte(void)
{
uint8_t data = 0;
data = UCB0RXBUF;
return data;
}
void i2c_give_nack(void)
{
UCB0CTL1 |= UCTXNACK;
while(UCB0CTL1 & UCTXNACK);
}
void rtc_write_reg(uint8_t addr, uint8_t data)
{
UCB0I2CSA = RTC_ADDRESS; // Slave Address is 048h
i2c_start(); //send start condition and slave address
i2c_write_byte(addr);
i2c_write_byte(data);
i2c_stop();
}
uint8_t rtc_read_reg(uint8_t addr)
{
uint8_t result;
UCB0I2CSA = RTC_ADDRESS; // Slave Address
i2c_start();
i2c_write_byte(addr);
UCB0I2CSA = RTC_ADDRESS | I2C_READ; // Slave Address with read option
i2c_repeated_start();
result = i2c_read_byte();
i2c_give_nack();
i2c_stop();
return result;
}
int main(void)
{
uint8_t data = 0;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
while (1)
{
rtc_write_reg(SECONDS,10);
__delay_cycles(90000);
data = rtc_read_reg(SECONDS);
__delay_cycles(90000);
}
}
//===========================================================================================
Please try to solve my above two query.any help in this will be appreciated more.
Thank You
Bhavin