energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
795 stars 671 forks source link

msp430g2553 RTC issue #215

Closed ampnayak closed 11 years ago

ampnayak commented 11 years ago

Dear all.

I m using Energia IDE,MSP430g2553 and DS1307 RTC.

I write the code using wire library from Energia. The code seems working fine with RTC pins SCL and SDA connected. AS soon as i remove the pin it will hang the cpu and stop executing . If connected back again start working. If same thing done with Arduino and pic controller seems working and when pins are removed they used to read default values. Please let me know how to solve this issue

I used the above technique as mention in thread but it didn't worked. IE adding pull u resistor in post 2. i have attach the code below. It is working fine with RTC connected and as soon as i removed code gets hang and stop printing time and other statements.

from forum

post1: /// If I understand correctly then reading from the DS1307 is working fine and it prints the time. But as soon as you remove the SDA/SCL lines the code hangs and stops printing the time? Is that correct? Can you post the Sketch you used? vaguely remember that if you try to read from I2C when there is not device present on the bus the I2C bus can indeed hang altogether. I'll give it a try..

////

post2: /// The USCI block gets into a funny state when SDA/SCL are floating (i.e nothing connected). The User Manual is pretty explicit about pullups on the I2C lines: "Both SDA and SCL are bidirectional, and must be connected to a positive supply voltage using a pullup resistor".

In your case, I would not worry about nothing being printed when you remove the device from the I2C bus. If you really want to have it execute normally then you can add a 10k pullup to the SDA and SCL lines.

Be careful with the 5v (TTL) since the MSP430 is a 3.3v (CMOS) device

///

my code:

include

define DS1307_ADDRESS 0x68

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

int second ; int m ; int hour; int weekday; int monthDay; int month; int year;

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 m =29; //0-59 byte hour =8; //0-23 byte weekday=2; byte monthDay =23; //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(m)); 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(zero);

Wire.endTransmission();

Wire.requestFrom(0x68,7);

//Serial.println(Wire.available()); if(Wire.available()>0) { second = bcdToDec(Wire.read()); m = bcdToDec(Wire.read()); hour = bcdToDec(Wire.read() & 0b111111); //24 hour time weekday=bcdToDec(Wire.read()); monthDay = bcdToDec(Wire.read()); month = bcdToDec(Wire.read()); year = bcdToDec(Wire.read()); }else Serial.println("data not received");

}

void printDate(){

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

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

Serial.print(year); Serial.print(" "); Serial.print(hour); Serial.print(":"); Serial.print(m); Serial.print(":"); Serial.println(second);

}

rei-vilo commented 11 years ago

Are the pins SCL and SDA connected to pull-up resistors —typically 4.7 kΩ or 10 kΩ?

Otherwise, they float and produce random signal.

robertinant commented 11 years ago

Pullups are needed otherwise the USCI block will hang. Also see my reply here: http://forum.43oh.com/topic/3554-rtc-problem/

ampnayak commented 11 years ago

I used the above technique as mention in thread but it didn't worked. IE adding pull u resistor in post 2. i have attach the code below. It is working fine with RTC connected and as soon as i removed code gets hang and stop printing time and other statements.

from forum

post1: /// If I understand correctly then reading from the DS1307 is working fine and it prints the time. But as soon as you remove the SDA/SCL lines the code hangs and stops printing the time? Is that correct? Can you post the Sketch you used? vaguely remember that if you try to read from I2C when there is not device present on the bus the I2C bus can indeed hang altogether. I'll give it a try..

////

post2: /// The USCI block gets into a funny state when SDA/SCL are floating (i.e nothing connected). The User Manual is pretty explicit about pullups on the I2C lines: "Both SDA and SCL are bidirectional, and must be connected to a positive supply voltage using a pullup resistor".

In your case, I would not worry about nothing being printed when you remove the device from the I2C bus. If you really want to have it execute normally then you can add a 10k pullup to the SDA and SCL lines.

Be careful with the 5v (TTL) since the MSP430 is a 3.3v (CMOS) device

///

my code:

include

define DS1307_ADDRESS 0x68

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

int second ; int m ; int hour; int weekday; int monthDay; int month; int year;

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 m =29; //0-59 byte hour =8; //0-23 byte weekday=2; byte monthDay =23; //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(m)); 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(zero);

Wire.endTransmission();

Wire.requestFrom(0x68,7);

//Serial.println(Wire.available()); if(Wire.available()>0) { second = bcdToDec(Wire.read()); m = bcdToDec(Wire.read()); hour = bcdToDec(Wire.read() & 0b111111); //24 hour time weekday=bcdToDec(Wire.read()); monthDay = bcdToDec(Wire.read()); month = bcdToDec(Wire.read()); year = bcdToDec(Wire.read()); }else Serial.println("data not received");

}

void printDate(){

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

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

Serial.print(year); Serial.print(" "); Serial.print(hour); Serial.print(":"); Serial.print(m); Serial.print(":"); Serial.println(second);

}

ampnayak commented 11 years ago

The reason for stressing above issue is. Our application depend on time. We done programming on arduino and pic controller . where even the i2c is disconnected they not even hang and they read default value as 0.0.0 0.0.0 as date and time.

Assume that if RTC get fails, Here in above case we cant predict whether it going to hang or read default value has Zero or garbage value. If didnt worked what is alternate solution

gopichinnasamy commented 8 years ago

hello sir, i got your post1 program....... can i get the same RTC program for tm4c123gh6pm lanuch pad.....please

rei-vilo commented 8 years ago

For the LM4F120 / TM4C123, have a look at DateTimeLibrary, RTC for MSP432 and TM4C, plus NTP for CC3200.

hemangjoshi37a commented 7 years ago

Anyone had found the solution for MSP430g2553?? My msp is reading all zeroes in the serial monitor when monitoring and debugguging the real time data.

Please someone help fast.

THank you.