Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

msp430g2553 i2c code for rtc Ds1307 is not working

$
0
0

Hi,

    I am using msp430g2553 uc and i am trying to communicae with ds1307. But i am not getting any data from ds1307. so please look at my code. if any modifications are required please let me know.


#include <msp430.h>

void i2c_Setup(void);
void i2c_Start();
void i2c_Stop();
static int count;
int RXdata[9];

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
P1OUT = 0x00;

P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0

P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0

//_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt

i2c_Setup();
i2c_Start();
UCB0TXBUF=0x01; // RTC start address in read mode
i2c_Start();
for(count=0;count<9;count++)
{
while(!UCB0RXIFG==1);
RXdata[count]=UCB0RXBUF;
}
i2c_Stop();
}

void i2c_Setup(void){

_DINT();
IE2 &= ~UCB0TXIE;
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;
UCB0I2CSA = 0xD0; // Slave Address is 68h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE; // Enable RX interrupt
}

void i2c_Start(){
UCB0CTL1 |= UCTXSTT; // I2C start condition
}

void i2c_Stop(){
UCB0CTL1 |= UCTXSTP; // I2C stop condition
}


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>