AMPS 0 Posted February 27, 2013 Share Posted February 27, 2013 I have copied code from Arduino and posted on energia . I found most of code working similar to arduino. Can some one tell me how below code make it work. I think i need to change the address . Please let me know how to get below address and change it #define DS1307_ADDRESS 0x68 #include"Wire.h"#define DS1307_ADDRESS 0x68byte zero = 0x00; //workaround for issue #527void setup(){ Wire.begin(); Serial.begin(9600); setDateTime(); //MUST CONFIGURE IN FUNCTION}void loop(){ printDate(); delay(1000);}void setDateTime(){ byte second = 45; //0-59 byte minute = 06; //0-59 byte hour = 11; //0-23 byte weekDay = 2; //1-7 byte monthDay = 27; //1-31 byte month = 2; //1-12 byte year = 13; //0-99 Wire.beginTransmission(DS1307_ADDRESS); Wire.write(zero); //stop Oscillator Wire.write(decToBcd(second)); Wire.write(decToBcd(minute)); 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 printDate(){ // Reset the register pointer Wire.beginTransmission(DS1307_ADDRESS); Wire.write(zero); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS, 7); int second = bcdToDec(Wire.read()); int minute = bcdToDec(Wire.read()); int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time int weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday int monthDay = bcdToDec(Wire.read()); int month = bcdToDec(Wire.read()); int year = bcdToDec(Wire.read()); /* int second = 11; int minute =18; int hour = 18; int weekDay = 1; int monthDay = 2; int month = 11; int year = 12;*/ //print the date EG 3/1/11 23:59:59 Serial.print(monthDay); Serial.print("/"); Serial.print(month); Serial.print("/"); Serial.print(year); Serial.print(" "); Serial.print(hour); Serial.print(":"); Serial.print(minute); Serial.print(":"); Serial.println(second);} Quote Link to post Share on other sites
energia 485 Posted February 28, 2013 Share Posted February 28, 2013 As mentioned in this thread: http://forum.43oh.com/topic/2153-real-time-clock-rtc-library-for-the-msp430launchpad/page-5 the DS1307 requires a 5 volt supply. There are some posts in this forum that talk about 5 volt sensor info like this one: http://forum.43oh.com/topic/2470-hc-sr04-ultrasonic-sensor-w-energia/?hl=%2Brange+%2Bsensor#entry22060 Quote Link to post Share on other sites
AMPS 0 Posted March 4, 2013 Author Share Posted March 4, 2013 I am having external 5v dc Power supply to power up DS1307. I have acheived answer in arduino but i could not able to acheive in MSP kits. It will write answer in serial monitor will not stay for long time As mentioned in this thread: http://forum.43oh.com/topic/2153-real-time-clock-rtc-library-for-the-msp430launchpad/page-5 the DS1307 requires a 5 volt supply. There are some posts in this forum that talk about 5 volt sensor info like this one: http://forum.43oh.com/topic/2470-hc-sr04-ultrasonic-sensor-w-energia/?hl=%2Brange+%2Bsensor#entry22060 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.