danigom 2 Posted May 22, 2013 Author Share Posted May 22, 2013 When you press Reset on the LaunchPad, does it display "RTC is not running!"? Yes!! Each time I press the Reset Button, it display "RTC is not running!" If I change ... int i = 0; with uint8_t i = 0; it doesn't compile. I'm starting to lose my temper, should change module? :shock: Quote Link to post Share on other sites
simpleavr 399 Posted May 22, 2013 Share Posted May 22, 2013 I have done some modifications: If I supply the RTC DS1307 Module with 3.6V from the Launchpad instead of 5V it works, but not correctly: the DS1307 datasheet says supply voltage is 4.5V+, at 3.6V it's just keeping time. i doubt u are reading anything meaningful, if at all. i don't think u can reliably do this as the data pin is bi-directional. there is this tip / guide on what options are available for interfacing 3v <> 5v devices but i don't see something simple that does bi-directional. http://www.newark.com/pdfs/techarticles/microchip/3_3vto5vAnalogTipsnTricksBrchr.pdf the PCF8563 is pin compatible w/ the DS1307 and works happily at 3V. it cost around $1.00/pc at ebay. Quote Link to post Share on other sites
chicken 630 Posted May 22, 2013 Share Posted May 22, 2013 Don't give up yet, we haven't even identified the actual issue If that won't compile, please respond with the actual error message. Otherwise it's hard to guess what went wrong. That being said, there are several things that could go wrong, including some know issues with I2C in the last official release of Energia. Here a basic test program that you could use in a fresh Energia sketch to at least rule out issues with the library and Energia itself. #include <Wire.h> void setup () { Serial.begin(9600); Wire.begin(); } void loop() { Wire.beginTransmission(0x68); Wire.write((uint8_t) 0); Wire.endTransmission(); Wire.requestFrom(0x68, 7); uint8_t ss = Wire.read(); uint8_t mm = Wire.read(); uint8_t hh = Wire.read(); Wire.read(); uint8_t d = Wire.read(); uint8_t m = Wire.read(); uint8_t y = Wire.read(); Serial.print("raw RTC data "); Serial.print(ss); Serial.print("\t"); Serial.print(mm); Serial.print("\t"); Serial.print(hh); Serial.print("\t"); Serial.print(d); Serial.print("\t"); Serial.print(m); Serial.print("\t"); Serial.println(y); delay(1000); } Hope that compiles, just writing/copying blindly without Energia right now Make sure to power cycle the LaunchPad (i.e. unplug / replug the USB cable) to rule out any hardware issues from previous attempts. If you still get garbage (e.g. all 255 or 0), then it's time to check your wiring.. or listen to the others and get a 3.3V compatible module, but where's the fun with that? danigom 1 Quote Link to post Share on other sites
chicken 630 Posted May 22, 2013 Share Posted May 22, 2013 the DS1307 datasheet says supply voltage is 4.5V+, at 3.6V it's just keeping time. i doubt u are reading anything meaningful, if at all. i don't think u can reliably do this as the data pin is bi-directional. there is this tip / guide on what options are available for interfacing 3v <> 5v devices but i don't see something simple that does bi-directional. http://www.newark.com/pdfs/techarticles/microchip/3_3vto5vAnalogTipsnTricksBrchr.pdf the PCF8563 is pin compatible w/ the DS1307 and works happily at 3V. it cost around $1.00/pc at ebay. Not sure how well the MSP430 handles 5V on its SCL/SDA, but with the pull-ups I think transmission to the DS1307 should work if the module is powered from 5V. Quote Link to post Share on other sites
cde 334 Posted May 22, 2013 Share Posted May 22, 2013 The schematic shows 3.3k pull ups on each line. You would need a level translator ic, or you could use two mosfets or four transistors to make your own: From http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter OzGrant 1 Quote Link to post Share on other sites
cde 334 Posted May 22, 2013 Share Posted May 22, 2013 Or actually, the DS1307 recognizes a Logic High as 2.2v to Vcc + 0.5. You could add the i2c Pull ups connected to 3.6v, instead of the 5v. You would need to disconnect the included ones (cut the traces), then add pullups (4.7k) to the launchpad VCC. Quote Link to post Share on other sites
Rei Vilo 695 Posted May 22, 2013 Share Posted May 22, 2013 I've published a full page about the 3.3V to 5V logic level converter. danigom 1 Quote Link to post Share on other sites
danigom 2 Posted May 23, 2013 Author Share Posted May 23, 2013 Don't give up yet, we haven't even identified the actual issue If that won't compile, please respond with the actual error message. Otherwise it's hard to guess what went wrong. That being said, there are several things that could go wrong, including some know issues with I2C in the last official release of Energia. Here a basic test program that you could use in a fresh Energia sketch to at least rule out issues with the library and Energia itself. #include <Wire.h> void setup () { Serial.begin(9600); Wire.begin(); } void loop() { Wire.beginTransmission(0x68); Wire.write((uint8_t) 0); Wire.endTransmission(); Wire.requestFrom(0x68, 7); uint8_t ss = Wire.read(); uint8_t mm = Wire.read(); uint8_t hh = Wire.read(); Wire.read(); uint8_t d = Wire.read(); uint8_t m = Wire.read(); uint8_t y = Wire.read(); Serial.print("raw RTC data "); Serial.print(ss); Serial.print("\t"); Serial.print(mm); Serial.print("\t"); Serial.print(hh); Serial.print("\t"); Serial.print(d); Serial.print("\t"); Serial.print(m); Serial.print("\t"); Serial.println(y); delay(1000); } Hope that compiles, just writing/copying blindly without Energia right now Make sure to power cycle the LaunchPad (i.e. unplug / replug the USB cable) to rule out any hardware issues from previous attempts. If you still get garbage (e.g. all 255 or 0), then it's time to check your wiring.. or listen to the others and get a 3.3V compatible module, but where's the fun with that? I am sorry, I was wrong. The program compiles with the following modification (I don't know why yesterday didn't): uint8_t i = 0; //The new wire library needs to take an int when you are sending for the zero register With this modification I get two different results. When I supply the module with +5V It doesn't show any communication: But when I supply the module with 3.3V I get this (something curious happens): On the other hand, i've tried with the following sketch: #include <Wire.h> void setup () { Serial.begin(9600); Wire.begin(); } void loop() { Wire.beginTransmission(0x68); Wire.write((uint8_t) 0); Wire.endTransmission(); Wire.requestFrom(0x68, 7); uint8_t ss = Wire.read(); uint8_t mm = Wire.read(); uint8_t hh = Wire.read(); Wire.read(); uint8_t d = Wire.read(); uint8_t m = Wire.read(); uint8_t y = Wire.read(); Serial.print("raw RTC data "); Serial.print(ss); Serial.print("\t"); Serial.print(mm); Serial.print("\t"); Serial.print(hh); Serial.print("\t"); Serial.print(d); Serial.print("\t"); Serial.print(m); Serial.print("\t"); Serial.println(y); delay(1000); } And I also get two different things, when i supply the module with 5Volt I get nothing, but when I supply it with 3.3V I get this: I think this demonstrates that the module is incompatible. Isn't it? chicken 1 Quote Link to post Share on other sites
danigom 2 Posted May 23, 2013 Author Share Posted May 23, 2013 I've published a full page about the 3.3V to 5V logic level converter. Thank you!! I've just read it and it's cool. Quote Link to post Share on other sites
chicken 630 Posted May 23, 2013 Share Posted May 23, 2013 I think this demonstrates that the module is incompatible. Isn't it? Unfortunately I think that's the conclusion. Quote Link to post Share on other sites
chicken 630 Posted May 23, 2013 Share Posted May 23, 2013 Actually, one last thing: Pull the jumper to the LED on P1.6, powering the LED might conflict with the I2C communication. danigom 1 Quote Link to post Share on other sites
danigom 2 Posted May 23, 2013 Author Share Posted May 23, 2013 Actually, one last thing: Pull the jumper to the LED on P1.6, powering the LED might conflict with the I2C communication. I'm sorry, it was already removed ;-) . Anyway, thank you very much for all the time spent. You're great people !! Quote Link to post Share on other sites
tranduythai 1 Posted September 18, 2013 Share Posted September 18, 2013 Hi everybody. I use library wire and lcd to read DS1307. Sometime system working, but i dont know why sometime, system dont read data from ds1307. And then i unplug SDA wire, and plug again system is working. I dont understand, please help me. My code #include <Wire.h> #include <LiquidCrystal.h> LiquidCrystal lcd(P2_0, P2_1, P2_2, P2_3, P2_4, P2_5); int clockAddress = 0x68; // This is the I2C address ds1307 int command = 0; // This is the command char, in ascii form, sent from the serial port long previousMillis = 0; // will store last time Temp was updated byte second, minute, hour, dayOfWeek, dayOfMonth, month, year,ktra; byte test; unsigned char NC1[24] ={0, 45, 58, 59, 40, 25, 35, 20, 25, 10, 15, 0, 0, 45, 50, 35, 40, 25, 35, 20, 25, 10, 15, 0}; unsigned char NC2[24] ={7, 7, 0, 0, 8, 9, 9, 10, 10, 11, 11, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17,18}; unsigned char TC1[2] ={0, 50}; unsigned char TC2[11] ={7,8,9,10,11,12,13,14,15,16,17}; byte decToBcd(byte val) { return ( (val/10*16) + (val%10) ); } // Convert binary coded decimal to normal decimal numbers byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); } void baogionienche() { unsigned char i; for(i=0;i<25;i++) { if((hour==NC2)&(minute==NC1)&(second==0)) { digitalWrite(RED_LED, HIGH); delay(3000); digitalWrite(RED_LED, LOW); delay(3000); digitalWrite(RED_LED, HIGH); delay(3000); digitalWrite(RED_LED, LOW); } } digitalWrite(RED_LED, LOW); } void setDateDs1307() { // Use of (byte) type casting and ascii math to achieve result. second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48)); minute = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); hour = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); dayOfWeek = (byte) (Serial.read() - 48); dayOfMonth = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); month = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); year= (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); Wire.beginTransmission(clockAddress); Wire.write(byte(0x00)); // Wire.write(decToBcd(second)); // 0 to bit 7 starts the clock // Wire.write(decToBcd(minute)); // Wire.write(decToBcd(hour)); // If you want 12 hour am/pm you need to set // // bit 6 (also need to change readDateDs1307) // Wire.write(decToBcd(dayOfWeek)); // Wire.write(decToBcd(dayOfMonth)); // Wire.write(decToBcd(month)); // Wire.write(decToBcd(year)); Wire.endTransmission(); } void Lcd_Chr(unsigned char col, unsigned char row,unsigned char neg) { lcd.setCursor(row-1,col); lcd.print (neg); } // Gets the date and time from the ds1307 and prints result void getDateDs1307() { // Reset the register pointer Wire.beginTransmission(clockAddress); Wire.write(byte(0x00)); Wire.endTransmission(); Wire.requestFrom(clockAddress, 7); // A few of these need masks because certain bits are control bits second = bcdToDec(Wire.read() & 0x7f); minute = bcdToDec(Wire.read()); // Need to change this if 12 hour am/pm hour = bcdToDec(Wire.read() & 0x3f); dayOfWeek = bcdToDec(Wire.read()); dayOfMonth = bcdToDec(Wire.read()); month = bcdToDec(Wire.read()); year = bcdToDec(Wire.read()); } void hienthi() { lcd.setCursor(0, 0); lcd.print("Time: : : "); lcd.setCursor(0, 1); lcd.print(" . . "); Lcd_Chr(0,9, (hour / 10)); Lcd_Chr(0,10, (hour % 10)); Lcd_Chr(0,12, (minute / 10)); Lcd_Chr(0,13, (minute % 10)); Lcd_Chr(0,15, (second / 10)); Lcd_Chr(0,16, (second % 10)); Lcd_Chr(1, 9, (dayOfMonth / 10)); Lcd_Chr(1, 10,(dayOfMonth % 10)); Lcd_Chr(1, 12,(month / 10)); Lcd_Chr(1,13, (month % 10)); Lcd_Chr(1,15, (year / 10)); Lcd_Chr(1,16, (year % 10)); lcd.setCursor(0, 1); switch (dayOfWeek) { case 1: // your hand is on the sensor lcd.print("Mon"); break; case 2: // your hand is close to the sensor lcd.print("Tue"); break; case 3: // your hand is close to the sensor lcd.print("Wed"); break; case 4: // your hand is close to the sensor lcd.print("Thu"); break; case 5: // your hand is close to the sensor lcd.print("Fri"); break; case 6: // your hand is close to the sensor lcd.print("Sat"); break; case 7: // your hand is close to the sensor lcd.print("Sun"); break; } } void setup() { Wire.begin(); Serial.begin(9600); lcd.begin(16, 2); lcd.print("hello, world!"); pinMode(RED_LED, OUTPUT); ktra=0; // Wire.beginTransmission(clockAddress); // Wire.write(byte(0x00)); // Wire.write(byte(0x00)); // Wire.endTransmission(); } void loop() { getDateDs1307(); if(second>ktra|second==0) { hienthi(); ktra=second; digitalWrite(RED_LED, HIGH); delay(200); digitalWrite(RED_LED, LOW); } baogionienche(); //hienthi(); //delay(200); } Quote Link to post Share on other sites
energia 485 Posted September 18, 2013 Share Posted September 18, 2013 Do you have pull-up resistors on the SDA and SCK lines? Without pull-ups the pins end up floating resulting in undefined behavior. This indeed might sometimes work but will eventually break. Quote Link to post Share on other sites
tranduythai 1 Posted September 19, 2013 Share Posted September 19, 2013 I have R 10k in SDA and SCL, so that board works well with CCS code. In CCS code, I dont setting put up in P1.6, P1.7. Finally, i have to put 2 R in SDA & SCL to work with Energia code? Thanks a lot 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.