Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RTC is hanging problem with msp

Status
Not open for further replies.

ajitnayak

Junior Member level 2
Joined
Feb 22, 2013
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,447
View attachment RTC.zipDear all,

I am using Ds1307 with MSPg430 kit and Energia as IDE which work similar to Arduino IDE.When i connect RTC pin i.e sda and scl they seems working.when i removed the program get hangs. If connected back it starts working fine.

Please let me know whether this behavior is normal or abnormal for MSP kits.

Code:
#include <Wire.h>


#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527

int s ;
int m ;
  int h;
  int w;
  int dd;
  int mm;
  int yy;



void setup(){
  Wire.begin();
 
  Serial.begin(9600);
  setDateTime(); //MUST CONFIGURE IN FUNCTION
}

void loop(){

  Serial.println("Welcome to MSP main program");
  getdate();
 printDate();
 Serial.println("read data from RTC");
 delay(1000);
 Serial.println("leaving the main");
  
}

void setDateTime(){

  byte second =45; //0-59
  byte minu =11; //0-59
  byte hour =13; //0-23
  byte weekday=2;
  byte monthDay =19; //1-31
  byte month =3; //1-12
  byte year  =13; //0-99



  Wire.beginTransmission(DS1307_ADDRESS);

  Wire.write(zero); //stop Oscillator

  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minu));
  Wire.write(decToBcd(hour));
  Wire.write(decToBcd(weekday));
  Wire.write(decToBcd(monthDay));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));

  Wire.write(zero); //start

  Wire.endTransmission();

}

byte decToBcd(byte val){
  // Convert normal decimal numbers to binary coded decimal
  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)  {
  // Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}


void getdate()
{
  
  Wire.beginTransmission(DS1307_ADDRESS);

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

  Wire.requestFrom(DS1307_ADDRESS,7);

s = bcdToDec(Wire.read());
 m = bcdToDec(Wire.read());
h = bcdToDec(Wire.read() & 0b111111); //24 hour time
w=bcdToDec(Wire.read());
dd= bcdToDec(Wire.read());
mm= bcdToDec(Wire.read());
yy = bcdToDec(Wire.read());
}


void printDate(){

  
  Serial.print(dd);
  Serial.print("/");


  Serial.print(mm);
  Serial.print("/");

  Serial.print(yy);
  Serial.print(" ");
  Serial.print(h);
  Serial.print(":");
  Serial.print(m);
  Serial.print(":");
  Serial.println(s);

}
 

dheena

Newbie level 6
Joined
Jan 31, 2011
Messages
13
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Location
Erode
Activity points
1,338
seems the program needs to get ACK from RTC and if it wont get any ACK it just hang on into a infinite loop...so modify your coding as like that...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top