EmbeddedRelated.com
Forums

RTC Code help

Started by Technical Kripa June 27, 2009
Pls help me on this. Pls refer to the code below for getting data from RTC. I am getting 00h for seconds and I get C0h for all others...minutes to years. I am working on IAR and RTC is DS1307. Connections with MSP430 is P5.7 to SDA and P5.6 to SCL

Thanks in advance
Sanmeet

code:
//*****************************************************************************
// DS1307 C Code
// SCL - P 5.6
// SDA - P 5.7
//*****************************************************************************
#include // Header files
#define SDA BIT7// SDA P5.7
#define SCL BIT6// SCL P5.6
#define SDA_Low P5DIR |= SDA; // Making SDA Line Low
#define SCL_Low P5DIR |= SCL; // Making SCL Line Low
#define SDA_High P5DIR &= ~SDA; // Making SDA Line High
#define SCL_High P5DIR &= ~SCL; // Making SCL Line High
#define RTC_write_addr 0xD0
#define RTC_read_addr 0xD1
#define RTC_regstr_addr 0x00
void delayrtc(void);
void I2C_Tx(int D);
void I2C_Clk(void);
void check_time(void);
void I2C_start(void);
int I2C_Rx(void);
void I2C_Ack(void);
void I2C_stop(void);
// Sec Min Hrs Day Date Month Year
char RTC[7]={0x01,0x30,0x05,0x02,0x28,0x11,0x08};
int main( void )
{
//clock init************
unsigned char k;
WDTCTL = WDT_ADLY_1000; // Stop WDT
/*Crystal Initilization*/
BCSCTL1 &= ~XTS;
BCSCTL1 &= ~XT2OFF; // XT2ON
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flagv d
for(k = 0xFF; k > 0; k--); // Time for flag to set
}while ((IFG1 & OFIFG) != 0); // Checking Oscillator fault flag
//-----------------------------
//Port init**************
P1DIR = 0;
P2DIR = 0;
P3DIR = 0;
P4DIR = 0;
P5DIR = 0;
P6DIR = 0;
P1OUT = 0;
P2OUT = 0;
P3OUT = 0;
P4OUT = 0;
P5OUT = 0;
P6OUT = 0;
//------------------------------
// check time *******************
for(;;)
{
unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_addr);delayrtc(); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_addr);delayrtc(); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start();delayrtc(); // I2C Start Condition
I2C_Tx(RTC_read_addr); // Transmitting DS1307 Read address
for(rtc_dat_cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt++)
{
delayrtc();
RTC[rtc_dat_cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc(); // Sending Received Acknowledge
}
}
I2C_stop();

}









}
void delayrtc(void)
{unsigned int delay_count;
for(delay_count = 0; delay_count <= 500; delay_count++);
}
void I2C_Tx(int D)
{unsigned char bCount;
unsigned int Data;
Data = D;
for(bCount = 0; bCount < 8; bCount++)
{
if((Data & BIT7) == 0x80)
{
SDA_High; delayrtc();
I2C_Clk(); delayrtc();
}
else if ((Data & BIT7) == 0)
{
SDA_Low; delayrtc();
I2C_Clk(); delayrtc();
}
Data <<= 1;
}
delayrtc();
SDA_High; delayrtc();
I2C_Clk(); // ACK Clock
}
void I2C_Clk(void)
{
delayrtc(); SCL_High;
delayrtc();
SCL_Low; delayrtc();
}
void check_time(void)
{ unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_addr);delayrtc(); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_addr);delayrtc(); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start();delayrtc(); // I2C Start Condition
I2C_Tx(RTC_read_addr); // Transmitting DS1307 Read address
for(rtc_dat_cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt++)
{
delayrtc();
RTC[rtc_dat_cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc(); // Sending Received Acknowledge
}
}
I2C_stop();
}
void I2C_start(void)
{
SDA_High; delayrtc();
SCL_High; delayrtc();
delayrtc(); delayrtc();
SDA_Low; delayrtc();
delayrtc(); delayrtc();
SCL_Low; delayrtc();
}
int I2C_Rx(void)
{unsigned char bCount;
unsigned int Temp, Data;
Data = 0;
for(bCount = 8; bCount > 0; bCount--)
{
SCL_High; delayrtc();
Temp = ((P5IN & BIT7) >> 1);
Data += (Temp << bCount-1);
SCL_Low;
delayrtc();
}
return(Data);
}
/*_______________________ I2C Master Acknowledge _____________________________*/
void I2C_Ack(void)
{
if((P3IN & BIT1) == 0x02)
{
SDA_Low;
delayrtc();
I2C_Clk(); // ACK Clock
delayrtc();
SDA_High;
}
}
/*_______________________ I2C Stop Condition _________________________________*/
void I2C_stop(void)
{
SDA_Low;
delayrtc();
SCL_High;
delayrtc();
SDA_High;
}
ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket.yahoo.com



Beginning Microcontrollers with the MSP430

I have run the whole program, in single step couple of times and made made the waveform on paper, but could not find the run or make the RTC talk. I also tried changing the RTC and my target board, but none combinations work. I think there is some silly mistake in the code itself. I hope someone here would time out to read the code and let me know where I faulted...

________________________________
From: Technical Kripa
To: MSP group
Sent: Saturday, 27 June, 2009 11:00:29 AM
Subject: [msp430] RTC Code help

Pls help me on this. Pls refer to the code below for getting data from RTC. I am getting 00h for seconds and I get C0h for all others...minutes to years. I am working on IAR and RTC is DS1307. Connections with MSP430 is P5.7 to SDA and P5.6 to SCL

Thanks in advance
Sanmeet

code:
//********** ********* ********* ********* ********* ********* ********* ********* ****
// DS1307 C Code
// SCL - P 5.6
// SDA - P 5.7
//********** ********* ********* ********* ********* ********* ********* ********* ****
#include // Header files
#define SDA BIT7// SDA P5.7
#define SCL BIT6// SCL P5.6
#define SDA_Low P5DIR |= SDA; // Making SDA Line Low
#define SCL_Low P5DIR |= SCL; // Making SCL Line Low
#define SDA_High P5DIR &= ~SDA; // Making SDA Line High
#define SCL_High P5DIR &= ~SCL; // Making SCL Line High
#define RTC_write_addr 0xD0
#define RTC_read_addr 0xD1
#define RTC_regstr_addr 0x00
void delayrtc(void) ;
void I2C_Tx(int D);
void I2C_Clk(void) ;
void check_time(void) ;
void I2C_start(void) ;
int I2C_Rx(void) ;
void I2C_Ack(void) ;
void I2C_stop(void) ;
// Sec Min Hrs Day Date Month Year
char RTC[7]={0x01, 0x30,0x05, 0x02,0x28, 0x11,0x08} ;
int main( void )
{
//clock init******** ****
unsigned char k;
WDTCTL = WDT_ADLY_1000; // Stop WDT
/*Crystal Initilization */
BCSCTL1 &= ~XTS;
BCSCTL1 &= ~XT2OFF; // XT2ON
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flagv d
for(k = 0xFF; k > 0; k--); // Time for flag to set
}while ((IFG1 & OFIFG) != 0); // Checking Oscillator fault flag
//---------- --------- --------- -
//Port init******** ******
P1DIR = 0;
P2DIR = 0;
P3DIR = 0;
P4DIR = 0;
P5DIR = 0;
P6DIR = 0;
P1OUT = 0;
P2OUT = 0;
P3OUT = 0;
P4OUT = 0;
P5OUT = 0;
P6OUT = 0;
//---------- --------- --------- --
// check time ************ *******
for(;;)
{
unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_ addr);delayrtc( ); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start(); delayrtc( ); // I2C Start Condition
I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc( ); // Sending Received Acknowledge
}
}
I2C_stop();

}









}
void delayrtc(void)
{unsigned int delay_count;
for(delay_count = 0; delay_count <= 500; delay_count+ +);
}
void I2C_Tx(int D)
{unsigned char bCount;
unsigned int Data;
Data = D;
for(bCount = 0; bCount < 8; bCount++)
{
if((Data & BIT7) == 0x80)
{
SDA_High; delayrtc();
I2C_Clk(); delayrtc();
}
else if ((Data & BIT7) == 0)
{
SDA_Low; delayrtc();
I2C_Clk(); delayrtc();
}
Data <<= 1;
}
delayrtc();
SDA_High; delayrtc();
I2C_Clk(); // ACK Clock
}
void I2C_Clk(void)
{
delayrtc(); SCL_High;
delayrtc();
SCL_Low; delayrtc();
}
void check_time(void)
{ unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_ addr);delayrtc( ); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start(); delayrtc( ); // I2C Start Condition
I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc( ); // Sending Received Acknowledge
}
}
I2C_stop();
}
void I2C_start(void)
{
SDA_High; delayrtc();
SCL_High; delayrtc();
delayrtc(); delayrtc();
SDA_Low; delayrtc();
delayrtc(); delayrtc();
SCL_Low; delayrtc();
}
int I2C_Rx(void)
{unsigned char bCount;
unsigned int Temp, Data;
Data = 0;
for(bCount = 8; bCount > 0; bCount--)
{
SCL_High; delayrtc();
Temp = ((P5IN & BIT7) >> 1);
Data += (Temp << bCount-1);
SCL_Low;
delayrtc();
}
return(Data) ;
}
/*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
void I2C_Ack(void)
{
if((P3IN & BIT1) == 0x02)
{
SDA_Low;
delayrtc();
I2C_Clk(); // ACK Clock
delayrtc();
SDA_High;
}
}
/*__________ _________ ____ I2C Stop Condition ____________ _________ _________ ___*/
void I2C_stop(void)
{
SDA_Low;
delayrtc();
SCL_High;
delayrtc();
SDA_High;
}

ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com



ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket.yahoo.com



I guess no one wants toanalyse a 2 page code. So I have narrowed down to one problem. I had adapted the code to work for me. The SCL and SDA ports are different from the code I adapted. After going thru several tutorials on I2C I came to a conclusion that the issue lies in the acknowledge function
/*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
void I2C_Ack(void)
{
if((P3IN & BIT1) == 0x02)
{
SDA_Low;
delayrtc();
I2C_Clk(); // ACK Clock
delayrtc();
SDA_High;
}
}
I didnt under stand what if((P3IN & BIT1) == 0x02) is for. My SCL is P5.6 and SDA is P5.7. How should this function be edited for my needs? Also why this "if" statement is thr? From wht Ive read and learnt, Ack requires a low SDA and a CLK pulse. Anyone still cares to guide?
SH

________________________________
From: Technical Kripa
To: m...
Sent: Monday, 29 June, 2009 9:32:31 AM
Subject: Re: [msp430] RTC Code help

I have run the whole program, in single step couple of times and made made the waveform on paper, but could not find the run or make the RTC talk. I also tried changing the RTC and my target board, but none combinations work. I think there is some silly mistake in the code itself. I hope someone here would time out to read the code and let me know where I faulted...

____________ _________ _________ __
From: Technical Kripa
To: MSP group
Sent: Saturday, 27 June, 2009 11:00:29 AM
Subject: [msp430] RTC Code help

Pls help me on this. Pls refer to the code below for getting data from RTC. I am getting 00h for seconds and I get C0h for all others...minutes to years. I am working on IAR and RTC is DS1307. Connections with MSP430 is P5.7 to SDA and P5.6 to SCL

Thanks in advance
Sanmeet

code:
//********** ********* ********* ********* ********* ********* ********* ********* ****
// DS1307 C Code
// SCL - P 5.6
// SDA - P 5.7
//********** ********* ********* ********* ********* ********* ********* ********* ****
#include // Header files
#define SDA BIT7// SDA P5.7
#define SCL BIT6// SCL P5.6
#define SDA_Low P5DIR |= SDA; // Making SDA Line Low
#define SCL_Low P5DIR |= SCL; // Making SCL Line Low
#define SDA_High P5DIR &= ~SDA; // Making SDA Line High
#define SCL_High P5DIR &= ~SCL; // Making SCL Line High
#define RTC_write_addr 0xD0
#define RTC_read_addr 0xD1
#define RTC_regstr_addr 0x00
void delayrtc(void) ;
void I2C_Tx(int D);
void I2C_Clk(void) ;
void check_time(void) ;
void I2C_start(void) ;
int I2C_Rx(void) ;
void I2C_Ack(void) ;
void I2C_stop(void) ;
// Sec Min Hrs Day Date Month Year
char RTC[7]={0x01, 0x30,0x05, 0x02,0x28, 0x11,0x08} ;
int main( void )
{
//clock init******** ****
unsigned char k;
WDTCTL = WDT_ADLY_1000; // Stop WDT
/*Crystal Initilization */
BCSCTL1 &= ~XTS;
BCSCTL1 &= ~XT2OFF; // XT2ON
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flagv d
for(k = 0xFF; k > 0; k--); // Time for flag to set
}while ((IFG1 & OFIFG) != 0); // Checking Oscillator fault flag
//---------- --------- --------- -
//Port init******** ******
P1DIR = 0;
P2DIR = 0;
P3DIR = 0;
P4DIR = 0;
P5DIR = 0;
P6DIR = 0;
P1OUT = 0;
P2OUT = 0;
P3OUT = 0;
P4OUT = 0;
P5OUT = 0;
P6OUT = 0;
//---------- --------- --------- --
// check time ************ *******
for(;;)
{
unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_ addr);delayrtc( ); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start(); delayrtc( ); // I2C Start Condition
I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc( ); // Sending Received Acknowledge
}
}
I2C_stop();

}









}
void delayrtc(void)
{unsigned int delay_count;
for(delay_count = 0; delay_count <= 500; delay_count+ +);
}
void I2C_Tx(int D)
{unsigned char bCount;
unsigned int Data;
Data = D;
for(bCount = 0; bCount < 8; bCount++)
{
if((Data & BIT7) == 0x80)
{
SDA_High; delayrtc();
I2C_Clk(); delayrtc();
}
else if ((Data & BIT7) == 0)
{
SDA_Low; delayrtc();
I2C_Clk(); delayrtc();
}
Data <<= 1;
}
delayrtc();
SDA_High; delayrtc();
I2C_Clk(); // ACK Clock
}
void I2C_Clk(void)
{
delayrtc(); SCL_High;
delayrtc();
SCL_Low; delayrtc();
}
void check_time(void)
{ unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_ addr);delayrtc( ); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start(); delayrtc( ); // I2C Start Condition
I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc( ); // Sending Received Acknowledge
}
}
I2C_stop();
}
void I2C_start(void)
{
SDA_High; delayrtc();
SCL_High; delayrtc();
delayrtc(); delayrtc();
SDA_Low; delayrtc();
delayrtc(); delayrtc();
SCL_Low; delayrtc();
}
int I2C_Rx(void)
{unsigned char bCount;
unsigned int Temp, Data;
Data = 0;
for(bCount = 8; bCount > 0; bCount--)
{
SCL_High; delayrtc();
Temp = ((P5IN & BIT7) >> 1);
Data += (Temp << bCount-1);
SCL_Low;
delayrtc();
}
return(Data) ;
}
/*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
void I2C_Ack(void)
{
if((P3IN & BIT1) == 0x02)
{
SDA_Low;
delayrtc();
I2C_Clk(); // ACK Clock
delayrtc();
SDA_High;
}
}
/*__________ _________ ____ I2C Stop Condition ____________ _________ _________ ___*/
void I2C_stop(void)
{
SDA_Low;
delayrtc();
SCL_High;
delayrtc();
SDA_High;
}

ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com



ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com



Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com



In the original code what was p3.1 defined as?? Was it SDA??


--- On Mon, 6/29/09, Technical Kripa wrote:
From: Technical Kripa
Subject: Re: [msp430] RTC Code help
To: m...
Date: Monday, June 29, 2009, 12:52 PM

I guess no one wants toanalyse a 2 page code. So I have narrowed down to one problem. I had adapted the code to work for me. The SCL and SDA ports are different from the code I adapted. After going thru several tutorials on I2C I came to a conclusion that the issue lies in the acknowledge function
/*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
void I2C_Ack(void)
{
if((P3IN & BIT1) == 0x02)
{
SDA_Low;
delayrtc();
I2C_Clk(); // ACK Clock
delayrtc();
SDA_High;
}
}
I didnt under stand what if((P3IN & BIT1) == 0x02) is for. My SCL is P5.6 and SDA is P5.7. How should this function be edited for my needs? Also why this "if" statement is thr? From wht Ive read and learnt, Ack requires a low SDA and a CLK pulse. Anyone still cares to guide?
SH

____________ _________ _________ __
From: Technical Kripa
To: msp430@yahoogroups. com
Sent: Monday, 29 June, 2009 9:32:31 AM
Subject: Re: [msp430] RTC Code help

I have run the whole program, in single step couple of times and made made the waveform on paper, but could not find the run or make the RTC talk. I also tried changing the RTC and my target board, but none combinations work. I think there is some silly mistake in the code itself. I hope someone here would time out to read the code and let me know where I faulted...

____________ _________ _________ __
From: Technical Kripa
To: MSP group
Sent: Saturday, 27 June, 2009 11:00:29 AM
Subject: [msp430] RTC Code help

Pls help me on this. Pls refer to the code below for getting data from RTC. I am getting 00h for seconds and I get C0h for all others...minutes to years. I am working on IAR and RTC is DS1307. Connections with MSP430 is P5.7 to SDA and P5.6 to SCL

Thanks in advance
Sanmeet

code:
//********** ********* ********* ********* ********* ********* ********* ********* ****
// DS1307 C Code
// SCL - P 5.6
// SDA - P 5.7
//********** ********* ********* ********* ********* ********* ********* ********* ****
#include // Header files
#define SDA BIT7// SDA P5.7
#define SCL BIT6// SCL P5.6
#define SDA_Low P5DIR |= SDA; // Making SDA Line Low
#define SCL_Low P5DIR |= SCL; // Making SCL Line Low
#define SDA_High P5DIR &= ~SDA; // Making SDA Line High
#define SCL_High P5DIR &= ~SCL; // Making SCL Line High
#define RTC_write_addr 0xD0
#define RTC_read_addr 0xD1
#define RTC_regstr_addr 0x00
void delayrtc(void) ;
void I2C_Tx(int D);
void I2C_Clk(void) ;
void check_time(void) ;
void I2C_start(void) ;
int I2C_Rx(void) ;
void I2C_Ack(void) ;
void I2C_stop(void) ;
// Sec Min Hrs Day Date Month Year
char RTC[7]={0x01, 0x30,0x05, 0x02,0x28, 0x11,0x08} ;
int main( void )
{
//clock init******** ****
unsigned char k;
WDTCTL = WDT_ADLY_1000; // Stop WDT
/*Crystal Initilization */
BCSCTL1 &= ~XTS;
BCSCTL1 &= ~XT2OFF; // XT2ON
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flagv d
for(k = 0xFF; k > 0; k--); // Time for flag to set
}while ((IFG1 & OFIFG) != 0); // Checking Oscillator fault flag
//---------- --------- --------- -
//Port init******** ******
P1DIR = 0;
P2DIR = 0;
P3DIR = 0;
P4DIR = 0;
P5DIR = 0;
P6DIR = 0;
P1OUT = 0;
P2OUT = 0;
P3OUT = 0;
P4OUT = 0;
P5OUT = 0;
P6OUT = 0;
//---------- --------- --------- --
// check time ************ *******
for(;;)
{
unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_ addr);delayrtc( ); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start(); delayrtc( ); // I2C Start Condition
I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc( ); // Sending Received Acknowledge
}
}
I2C_stop();

}









}
void delayrtc(void)
{unsigned int delay_count;
for(delay_count = 0; delay_count <= 500; delay_count+ +);
}
void I2C_Tx(int D)
{unsigned char bCount;
unsigned int Data;
Data = D;
for(bCount = 0; bCount < 8; bCount++)
{
if((Data & BIT7) == 0x80)
{
SDA_High; delayrtc();
I2C_Clk(); delayrtc();
}
else if ((Data & BIT7) == 0)
{
SDA_Low; delayrtc();
I2C_Clk(); delayrtc();
}
Data <<= 1;
}
delayrtc();
SDA_High; delayrtc();
I2C_Clk(); // ACK Clock
}
void I2C_Clk(void)
{
delayrtc(); SCL_High;
delayrtc();
SCL_Low; delayrtc();
}
void check_time(void)
{ unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_ addr);delayrtc( ); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start(); delayrtc( ); // I2C Start Condition
I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc( ); // Sending Received Acknowledge
}
}
I2C_stop();
}
void I2C_start(void)
{
SDA_High; delayrtc();
SCL_High; delayrtc();
delayrtc(); delayrtc();
SDA_Low; delayrtc();
delayrtc(); delayrtc();
SCL_Low; delayrtc();
}
int I2C_Rx(void)
{unsigned char bCount;
unsigned int Temp, Data;
Data = 0;
for(bCount = 8; bCount > 0; bCount--)
{
SCL_High; delayrtc();
Temp = ((P5IN & BIT7) >> 1);
Data += (Temp << bCount-1);
SCL_Low;
delayrtc();
}
return(Data) ;
}
/*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
void I2C_Ack(void)
{
if((P3IN & BIT1) == 0x02)
{
SDA_Low;
delayrtc();
I2C_Clk(); // ACK Clock
delayrtc();
SDA_High;
}
}
/*__________ _________ ____ I2C Stop Condition ____________ _________ _________ ___*/
void I2C_stop(void)
{
SDA_Low;
delayrtc();
SCL_High;
delayrtc();
SDA_High;
}

ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com



ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com



Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket. yahoo.com





Hi,
This is a bit messy. Makes my code look good. :)
Go to second part, *May 14, 2009*


Technical Kripa wrote:
> I guess no one wants to analyse a 2 page code. So I have narrowed down to one problem. I had adapted the code to work for me. The SCL and SDA ports are different from the code I adapted. After going thru several tutorials on I2C I came to a conclusion that the issue lies in the acknowledge function
> /*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
> void I2C_Ack(void)
> {
> if((P3IN & BIT1) == 0x02)
> {
> SDA_Low;
> delayrtc();
> I2C_Clk(); // ACK Clock
> delayrtc();
> SDA_High;
> }
> }
> I didnt under stand what if((P3IN & BIT1) == 0x02) is for.

It has no meaning if you copied and pasted this code. At that:

P3IN & BIT1

Has the same meaning as:

(P3IN & BIT1) == 0x02

The latter is just not clear and may not get optimized. I'll intersperse
comments below.

> code:
> //********** ********* ********* ********* ********* ********* ********* ********* ****
> // DS1307 C Code
> // SCL - P 5.6
> // SDA - P 5.7
> //********** ********* ********* ********* ********* ********* ********* ********* ****
> #include // Header files
> #define SDA BIT7 // SDA P5.7
> #define SCL BIT6 // SCL P5.6
> #define SDA_Low P5DIR |= SDA; // Making SDA Line Low
> #define SCL_Low P5DIR |= SCL; // Making SCL Line Low
> #define SDA_High P5DIR &= ~SDA; // Making SDA Line High
> #define SCL_High P5DIR &= ~SCL; // Making SCL Line High
>
The writer attempts to use defines for changes in use but fails to
follow through below...
> // check time ************ *******
>

I'll skip your code, it can be looked at later.

> }
> void delayrtc(void)
> {unsigned int delay_count;
> for(delay_count = 0; delay_count <= 500; delay_count+ +);
> }
>

I hope this is just for debugging and without optimization. Empty 'for
loops can disappear. And, unless you have an unusual need this delay is
way too long. I2C can be done very quickly in MSP430 time.

> void I2C_Tx(int D)
> {unsigned char bCount;
> unsigned int Data;
> Data = D;
> for(bCount = 0; bCount < 8; bCount++)
> {
> if((Data & BIT7) == 0x80)
>

Just 'if( data & 0x80 )' It is clearer, BIT7 has a port meaning.

> {
> SDA_High; delayrtc();
> I2C_Clk(); delayrtc();
> }
> else if ((Data & BIT7) == 0)
> {
> SDA_Low; delayrtc();
> I2C_Clk(); delayrtc();
> }
> Data <<= 1;
> }
> delayrtc();
> SDA_High; delayrtc();
> I2C_Clk(); // ACK Clock
> }
>

Where is the test of ack from the slave device!??
There are just way more delays than necessary. And there are delays that
wrap delays in called code, like here:

> void I2C_Clk(void)
> {
> delayrtc(); SCL_High;
> delayrtc();
> SCL_Low; delayrtc();
> }
>

You don't need a separate clock call, it can be done in I2C_Tx and I2C_Rx.

> void I2C_start(void)
> {
> SDA_High; delayrtc();
> SCL_High; delayrtc();
> delayrtc(); delayrtc();
> SDA_Low; delayrtc();
> delayrtc(); delayrtc();
> SCL_Low; delayrtc();
> }
>

So many needless delays.

> int I2C_Rx(void)
> {unsigned char bCount;
> unsigned int Temp, Data;
> Data = 0;
> for(bCount = 8; bCount > 0; bCount--)
> {
> SCL_High; delayrtc();
> Temp = ((P5IN & BIT7) >> 1);
> Data += (Temp << bCount-1);
>

Why so much needless code to read the data? Where, (and maybe I missed
it), does the author ever set SDA as an input so you can actually read
what the slave is transmitting? What good are the defines if you are
going to hard code P5IN & BIT7 down here?

> SCL_Low;
> delayrtc();
> }
> return(Data) ;
>

Where is the ack back to the slave device? Oh, that's right, it is your
job. It shouldn't be. You know how many bytes you will receive from the
slave and all you should have to do is pass the count. Instead of:

~~~

for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack(); delayrtc( ); // Sending Received Acknowledge
}
~~~

You could just:
i2cm_in( RTC, 7 );

Then you don't need to bloat your code every time you want to read slave data.

> }
> /*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
> void I2C_Ack(void)
> {
> if((P3IN & BIT1) == 0x02)
>

Yep, this is a mystery. But this code is so well commented it should
have been obvious. :)
Ack doesn't need its own call.

My code may not be perfect but I've used it on several devices so it is
proven. This stuff looks like it has never been tested.

BTW, do you have a link to where you got this?

Best, Dan.

Hi,

char RTC[7]={0x01,0x30,0x05,0x02,0x28,0x11,0x08};
You initalizer RTC as char, IAR don't initalizer it, maybe a BUG!
Here is a solution,
char RTC[7] // define global

init this in the main function
RTC[0] = 0x01;
...
RTC[6] = 0x08;

best regards
Bleaz

--- In m..., Joe Radomski wrote:
>
> In the original code what was p3.1 defined as?? Was it SDA??
> ?> ?>
>
> --- On Mon, 6/29/09, Technical Kripa wrote:
>
>
> From: Technical Kripa
> Subject: Re: [msp430] RTC Code help
> To: m...
> Date: Monday, June 29, 2009, 12:52 PM
>
>
>
>
>
>
>
>
> I guess no one wants toanalyse a 2 page code. So I have narrowed down to one problem. I had adapted the code to work for me. The SCL and SDA ports are different from the code I adapted. After going thru several tutorials on I2C I came to a conclusion that the issue lies in the acknowledge function
> /*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
> void I2C_Ack(void)
> {
> if((P3IN & BIT1) == 0x02)
> ?{
> ?SDA_Low;
> ?delayrtc();
> ?I2C_Clk(); // ACK Clock
> ?delayrtc();
> ?SDA_High;
> ?}
> }
> I didnt under stand what if((P3IN & BIT1) == 0x02) is for. My SCL is P5.6 and SDA is P5.7. How should this function be edited for my needs? Also why this "if" statement is thr? From wht Ive read and learnt, Ack requires a low SDA and a CLK pulse. Anyone still cares to guide?
> SH
>
> ____________ _________ _________ __
> From: Technical Kripa
> To: msp430@yahoogroups. com
> Sent: Monday, 29 June, 2009 9:32:31 AM
> Subject: Re: [msp430] RTC Code help
>
> I have run the whole program, in single step couple of times and made made the waveform on paper, but could not find the run or make the RTC talk. I also tried changing the RTC and my target board, but none combinations work. I think there is some silly mistake in the code itself. I hope someone here would time out to read the code and let me know where I faulted...
>
> ____________ _________ _________ __
> From: Technical Kripa
> To: MSP group
> Sent: Saturday, 27 June, 2009 11:00:29 AM
> Subject: [msp430] RTC Code help
>
> Pls help me on this. Pls refer to the code below for getting data from RTC. I am getting 00h for seconds and I get C0h for all others...minutes to years. I am working on IAR and RTC is DS1307. Connections with MSP430 is P5.7 to SDA and P5.6 to SCL
>
> Thanks in advance
> Sanmeet
>
> code:
> //********** ********* ********* ********* ********* ********* ********* ********* ****
> // DS1307 C Code
> //?SCL?- P 5.6
> //?SDA?- P 5.7
> //********** ********* ********* ********* ********* ********* ********* ********* ****
> #include ?// Header files
> #define SDA BIT7// SDA P5.7
> #define SCL BIT6// SCL P5.6
> #define SDA_Low?P5DIR?|=?SDA; // Making SDA Line Low
> #define SCL_Low?P5DIR?|=?SCL; // Making SCL Line Low
> #define SDA_High P5DIR?&= ~SDA; // Making SDA Line High
> #define SCL_High P5DIR?&= ~SCL; // Making SCL Line High
> #define RTC_write_addr?0xD0
> #define RTC_read_addr 0xD1
> #define RTC_regstr_addr 0x00
> void delayrtc(void) ;
> void I2C_Tx(int D);
> void I2C_Clk(void) ;
> void check_time(void) ;
> void I2C_start(void) ;
> int I2C_Rx(void) ;
> void I2C_Ack(void) ;
> void I2C_stop(void) ;
> //?Sec Min Hrs Day Date?Month Year
> char RTC[7]={0x01, 0x30,0x05, 0x02,0x28, 0x11,0x08} ;
> int main( void )
> {
> //clock init******** ****
> ?unsigned char k;
> ?WDTCTL = WDT_ADLY_1000; // Stop WDT
> ?/*Crystal Initilization?*/
> ?BCSCTL1 &=?~XTS;
> ?BCSCTL1 &= ~XT2OFF; // XT2ON
> ?do
> ?{
> ?IFG1 &= ~OFIFG; // Clear OSCFault flagv?d
> ?for(k = 0xFF; k > 0; k--);?// Time for flag to set
> ?}while ((IFG1 & OFIFG) != 0);??// Checking Oscillator fault flag
> ?//---------- --------- --------- -
> //Port init******** ******
> ?P1DIR = 0;
> ?P2DIR = 0;
> ?P3DIR = 0;
> ?P4DIR = 0;
> ?P5DIR = 0;
> ?P6DIR = 0;
> ?P1OUT = 0;
> ?P2OUT = 0;
> ?P3OUT = 0;
> ?P4OUT = 0;
> ?P5OUT = 0;
> ?P6OUT = 0;
> ?/---------- --------- --------- --
> // check time ************ *******
> ?for(;;)
> ?{
> ?unsigned char rtc_dat_cnt;
> ?I2C_start(); // I2C Start Condition
> ?I2C_Tx(RTC_write_ addr);delayrtc( );?// Transmitting DS1307 Write address
> ?I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
> ?I2C_stop();delayrtc(); // I2C Stop Condition
> ?I2C_start(); delayrtc( );?// I2C Start Condition
> ?I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
> ?for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
> ?{
> ?delayrtc();
> ?RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
> if(rtc_dat_cnt < 6)
> ?{
> I2C_Ack();delayrtc( );?// Sending Received Acknowledge
> ?}
> }
> ?I2C_stop();
> ?
> ?}
> ?
> ?
> ?
> ?
> ?
> ?
> ?
> ?
> ?> }
> void delayrtc(void)
> {unsigned int delay_count;
> for(delay_count = 0; delay_count <= 500; delay_count+ +);
> }
> void I2C_Tx(int D)
> {unsigned char bCount;
> ?unsigned int Data;
> ?Data = D;
> ?for(bCount = 0; bCount < 8; bCount++)
> {
> if((Data & BIT7) == 0x80)
> {
> SDA_High; delayrtc();
> I2C_Clk(); delayrtc();
> }
> else if ((Data & BIT7) == 0)
> {
> SDA_Low; delayrtc();
> I2C_Clk(); delayrtc();
> }
> Data <<= 1;
> }
> ?delayrtc();
> ?SDA_High; delayrtc();
> ?I2C_Clk();?// ACK Clock
> }
> void I2C_Clk(void)
> {
> delayrtc(); SCL_High;
> delayrtc();
> SCL_Low; delayrtc();
> }
> void check_time(void)
> { unsigned char rtc_dat_cnt;
> ?I2C_start(); // I2C Start Condition
> ?I2C_Tx(RTC_write_ addr);delayrtc( );?// Transmitting DS1307 Write address
> ?I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
> ?I2C_stop();delayrtc(); // I2C Stop Condition
> ?I2C_start(); delayrtc( );?// I2C Start Condition
> ?I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
> ?for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
> ?{
> ?delayrtc();
> ?RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
> if(rtc_dat_cnt < 6)
> ?{
> I2C_Ack();delayrtc( );?// Sending Received Acknowledge
> ?}
> }
> ?I2C_stop();
> }
> void I2C_start(void)
> {
> SDA_High; delayrtc();
> SCL_High; delayrtc();
> delayrtc();?delayrtc();
> SDA_Low; delayrtc();
> delayrtc(); delayrtc();
> SCL_Low; delayrtc();
> }
> int I2C_Rx(void)
> {unsigned char bCount;
> ?unsigned int Temp, Data;
> ?Data = 0;
> ?for(bCount = 8; bCount > 0; bCount--)
> {
> SCL_High; delayrtc();
> Temp = ((P5IN & BIT7) >> 1);
> Data += (Temp << bCount-1);
> SCL_Low;
> delayrtc();
> }
> ?return(Data) ;
> }
> /*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
> void I2C_Ack(void)
> {
> if((P3IN & BIT1) == 0x02)
> ?{
> ?SDA_Low;
> ?delayrtc();
> ?I2C_Clk(); // ACK Clock
> ?delayrtc();
> ?SDA_High;
> ?}
> }
> /*__________ _________ ____ I2C Stop Condition ____________ _________ _________ ___*/
> void I2C_stop(void)
> {
> SDA_Low;
> delayrtc();
> SCL_High;
> delayrtc();
> SDA_High;
> }
>
> ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com
>
>
>
> ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com
>
>
>
> Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket. yahoo.com
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>In the original code what was p3.1 defined as?? Was it SDA??
Original code p3.1 SDA and p3.3 SCL

________________________________
From: Joe Radomski
To: m...
Sent: Monday, 29 June, 2009 10:53:14 PM
Subject: Re: [msp430] RTC Code help

In the original code what was p3.1 defined as?? Was it SDA??



--- On Mon, 6/29/09, Technical Kripa wrote:

From: Technical Kripa
Subject: Re: [msp430] RTC Code help
To: msp430@yahoogroups. com
Date: Monday, June 29, 2009, 12:52 PM

I guess no one wants toanalyse a 2 page code. So I have narrowed down to one problem. I had adapted the code to work for me. The SCL and SDA ports are different from the code I adapted. After going thru several tutorials on I2C I came to a conclusion that the issue lies in the acknowledge function
/*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
void I2C_Ack(void)
{
if((P3IN & BIT1) == 0x02)
{
SDA_Low;
delayrtc();
I2C_Clk(); // ACK Clock
delayrtc();
SDA_High;
}
}
I didnt under stand what if((P3IN & BIT1) == 0x02) is for. My SCL is P5.6 and SDA is P5..7. How should this function be edited for my needs? Also why this "if" statement is thr? From wht Ive read and learnt, Ack requires a low SDA and a CLK pulse. Anyone still cares to guide?
SH

____________ _________ _________ __
From: Technical Kripa
To: msp430@yahoogroups. com
Sent: Monday, 29 June, 2009 9:32:31 AM
Subject: Re: [msp430] RTC Code help

I have run the whole program, in single step couple of times and made made the waveform on paper, but could not find the run or make the RTC talk. I also tried changing the RTC and my target board, but none combinations work. I think there is some silly mistake in the code itself. I hope someone here would time out to read the code and let me know where I faulted...

____________ _________ _________ __
From: Technical Kripa
To: MSP group
Sent: Saturday, 27 June, 2009 11:00:29 AM
Subject: [msp430] RTC Code help

Pls help me on this. Pls refer to the code below for getting data from RTC. I am getting 00h for seconds and I get C0h for all others...minutes to years. I am working on IAR and RTC is DS1307. Connections with MSP430 is P5.7 to SDA and P5.6 to SCL

Thanks in advance
Sanmeet

code:
//********** ********* ********* ********* ********* ********* ********* ********* ****
// DS1307 C Code
// SCL - P 5.6
// SDA - P 5.7
//********** ********* ********* ********* ********* ********* ********* ********* ****
#include // Header files
#define SDA BIT7// SDA P5.7
#define SCL BIT6// SCL P5.6
#define SDA_Low P5DIR |= SDA; // Making SDA Line Low
#define SCL_Low P5DIR |= SCL; // Making SCL Line Low
#define SDA_High P5DIR &= ~SDA; // Making SDA Line High
#define SCL_High P5DIR &= ~SCL; // Making SCL Line High
#define RTC_write_addr 0xD0
#define RTC_read_addr 0xD1
#define RTC_regstr_addr 0x00
void delayrtc(void) ;
void I2C_Tx(int D);
void I2C_Clk(void) ;
void check_time(void) ;
void I2C_start(void) ;
int I2C_Rx(void) ;
void I2C_Ack(void) ;
void I2C_stop(void) ;
// Sec Min Hrs Day Date Month Year
char RTC[7]={0x01, 0x30,0x05, 0x02,0x28, 0x11,0x08} ;
int main( void )
{
//clock init******** ****
unsigned char k;
WDTCTL = WDT_ADLY_1000; // Stop WDT
/*Crystal Initilization */
BCSCTL1 &= ~XTS;
BCSCTL1 &= ~XT2OFF; // XT2ON
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flagv d
for(k = 0xFF; k > 0; k--); // Time for flag to set
}while ((IFG1 & OFIFG) != 0); // Checking Oscillator fault flag
//---------- --------- --------- -
//Port init******** ******
P1DIR = 0;
P2DIR = 0;
P3DIR = 0;
P4DIR = 0;
P5DIR = 0;
P6DIR = 0;
P1OUT = 0;
P2OUT = 0;
P3OUT = 0;
P4OUT = 0;
P5OUT = 0;
P6OUT = 0;
//---------- --------- --------- --
// check time ************ *******
for(;;)
{
unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_ addr);delayrtc( ); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start(); delayrtc( ); // I2C Start Condition
I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc( ); // Sending Received Acknowledge
}
}
I2C_stop();

}









}
void delayrtc(void)
{unsigned int delay_count;
for(delay_count = 0; delay_count <= 500; delay_count+ +);
}
void I2C_Tx(int D)
{unsigned char bCount;
unsigned int Data;
Data = D;
for(bCount = 0; bCount < 8; bCount++)
{
if((Data & BIT7) == 0x80)
{
SDA_High; delayrtc();
I2C_Clk(); delayrtc();
}
else if ((Data & BIT7) == 0)
{
SDA_Low; delayrtc();
I2C_Clk(); delayrtc();
}
Data <<= 1;
}
delayrtc();
SDA_High; delayrtc();
I2C_Clk(); // ACK Clock
}
void I2C_Clk(void)
{
delayrtc(); SCL_High;
delayrtc();
SCL_Low; delayrtc();
}
void check_time(void)
{ unsigned char rtc_dat_cnt;
I2C_start(); // I2C Start Condition
I2C_Tx(RTC_write_ addr);delayrtc( ); // Transmitting DS1307 Write address
I2C_Tx(RTC_regstr_ addr);delayrtc( ); // Transmitting DS1307 Seconds address
I2C_stop();delayrtc(); // I2C Stop Condition
I2C_start(); delayrtc( ); // I2C Start Condition
I2C_Tx(RTC_read_ addr); // Transmitting DS1307 Read address
for(rtc_dat_ cnt = 0; rtc_dat_cnt < 7; rtc_dat_cnt+ +)
{
delayrtc();
RTC[rtc_dat_ cnt] = I2C_Rx(); // Receiving Time from DS1307 and storing
if(rtc_dat_cnt < 6)
{
I2C_Ack();delayrtc( ); // Sending Received Acknowledge
}
}
I2C_stop();
}
void I2C_start(void)
{
SDA_High; delayrtc();
SCL_High; delayrtc();
delayrtc(); delayrtc();
SDA_Low; delayrtc();
delayrtc(); delayrtc();
SCL_Low; delayrtc();
}
int I2C_Rx(void)
{unsigned char bCount;
unsigned int Temp, Data;
Data = 0;
for(bCount = 8; bCount > 0; bCount--)
{
SCL_High; delayrtc();
Temp = ((P5IN & BIT7) >> 1);
Data += (Temp << bCount-1);
SCL_Low;
delayrtc();
}
return(Data) ;
}
/*__________ _________ ____ I2C Master Acknowledge ____________ _________ ________* /
void I2C_Ack(void)
{
if((P3IN & BIT1) == 0x02)
{
SDA_Low;
delayrtc();
I2C_Clk(); // ACK Clock
delayrtc();
SDA_High;
}
}
/*__________ _________ ____ I2C Stop Condition ____________ _________ _________ ___*/
void I2C_stop(void)
{
SDA_Low;
delayrtc();
SCL_High;
delayrtc();
SDA_High;
}

ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com



ICC World Twenty20 England '09 exclusively on YAHOO! CRICKET http://cricket. yahoo.com



Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket. yahoo.com





Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com