danigom 2 Posted May 20, 2013 Share Posted May 20, 2013 (edited) Hello to everyone, I am new with MSP430 Launchpad and Energ Edited September 22, 2013 by bluehash [ADMIN] - Please upload pics to 43oh.com next time Quote Link to post Share on other sites
chicken 630 Posted May 20, 2013 Share Posted May 20, 2013 Looks like the RTCLib is using native AVR code, i.e. it needs some fixing to be portable beyond Arduino. Are you using the Adafruit library? https://github.com/adafruit/RTClib danigom 1 Quote Link to post Share on other sites
chicken 630 Posted May 20, 2013 Share Posted May 20, 2013 Taking a quick look at the code, you'll need to change at least the following: Remove this line, MSP430 can access data stored in ROM just fine without. 5: #include <avr/pgmspace.h> Related to this, remove PROGMEM directive here: (you might prefix the line with static) 23: const uint8_t daysInMonth [] PROGMEM = { 31,28,31,30,31,30,31,31,30,31,30,31 }; and access to the array has to be rewritten, original: 31: days += pgm_read_byte(daysInMonth + i - 1); .. 62: uint8_t daysPerMonth = pgm_read_byte(daysInMonth + m - 1); changed: 31: days += daysInMonth[i - 1]; .. 62: uint8_t daysPerMonth = daysInMonth[m - 1]; And finally, replace this section with #include "Energia.h" 13: #if (ARDUINO >= 100) 14: #include <Arduino.h> // capital A so it is error prone on case-sensitive filesystems 15: #else 16: #include <WProgram.h> 17: #endif Register and danigom 2 Quote Link to post Share on other sites
danigom 2 Posted May 20, 2013 Author Share Posted May 20, 2013 Taking a quick look at the code, you'll need to change at least the following: Remove this line, MSP430 can access data stored in ROM just fine without. 5: #include Related to this, remove PROGMEM directive here: (you might prefix the line with static) 23: const uint8_t daysInMonth [] PROGMEM = { 31,28,31,30,31,30,31,31,30,31,30,31 }; and access to the array has to be rewritten, original: 31: days += pgm_read_byte(daysInMonth + i - 1); .. 62: uint8_t daysPerMonth = pgm_read_byte(daysInMonth + m - 1); changed: 31: days += daysInMonth[i - 1]; .. 62: uint8_t daysPerMonth = daysInMonth[m - 1]; And finally, replace this section with #include "Energia.h" 13: #if (ARDUINO >= 100) 14: #include // capital A so it is error prone on case-sensitive filesystems 15: #else 16: #include 17: #endif First of all thank you for taking your time on it. Could you tell me how can I modify the library with energia IDE? (.cpp or .h file?) Thank you! Quote Link to post Share on other sites
cde 334 Posted May 20, 2013 Share Posted May 20, 2013 First of all thank you for taking your time on it. Could you tell me how can I modify the library with energia IDE? (.cpp or .h file?) Thank you! Simply open the RTClib.cpp or RTClib.h file like you would any other file. I suggest make a backup first. The files should be in (specifically in your case) D:\Desktop\Energ danigom 1 Quote Link to post Share on other sites
danigom 2 Posted May 20, 2013 Author Share Posted May 20, 2013 Looks like the RTCLib is using native AVR code, i.e. it needs some fixing to be portable beyond Arduino. Are you using the Adafruit library? https://github.com/adafruit/RTClib Yes, I'm using it! Quote Link to post Share on other sites
danigom 2 Posted May 21, 2013 Author Share Posted May 21, 2013 Taking a quick look at the code, you'll need to change at least the following: Remove this line, MSP430 can access data stored in ROM just fine without. 5: #include <avr/pgmspace.h> Related to this, remove PROGMEM directive here: (you might prefix the line with static) 23: const uint8_t daysInMonth [] PROGMEM = { 31,28,31,30,31,30,31,31,30,31,30,31 }; and access to the array has to be rewritten, original: 31: days += pgm_read_byte(daysInMonth + i - 1); .. 62: uint8_t daysPerMonth = pgm_read_byte(daysInMonth + m - 1); changed: 31: days += daysInMonth[i - 1]; .. 62: uint8_t daysPerMonth = daysInMonth[m - 1]; And finally, replace this section with #include "Energia.h" 13: #if (ARDUINO >= 100) 14: #include <Arduino.h> // capital A so it is error prone on case-sensitive filesystems 15: #else 16: #include <WProgram.h> 17: #endif I'm sorry, I could't fix it with these modifications. Could anyone tell me another library to work with this module? Quote Link to post Share on other sites
chicken 630 Posted May 21, 2013 Share Posted May 21, 2013 Does it compile? If not, what's the error? danigom 1 Quote Link to post Share on other sites
Rei Vilo 695 Posted May 21, 2013 Share Posted May 21, 2013 The specification sheet of the DS1307 says the supply voltage is min=4.5B typical=5V max=5.5V. How do you make the connection to the LaunchPad pins which are 3.3V-based? Two risks: data from the DS1307 may overload and fry the pins of the LaunchPad signal HIGH from the LaunchPad isn't high enough for the DS1307 and is considered as LOW by the DS1307 I suggest using the NXP PCF2129A instead. The PCF2129A operates at 3.3V, embeds the quartz crystal and requires no passive components. Rickta59 and danigom 2 Quote Link to post Share on other sites
danigom 2 Posted May 22, 2013 Author Share Posted May 22, 2013 The specification sheet of the DS1307 says the supply voltage is min=4.5B typical=5V max=5.5V. How do you make the connection to the LaunchPad pins which are 3.3V-based? Two risks: data from the DS1307 may overload and fry the pins of the LaunchPad signal HIGH from the LaunchPad isn't high enough for the DS1307 and is considered as LOW by the DS1307 I suggest using the NXP PCF2129A instead. The PCF2129A operates at 3.3V, embeds the quartz crystal and requires no passive components. I supply the RTC module with 5V directly from the USB Port although the connection with the Launchpad is 3.3V. I've attached two pictures so that you can see the connections: I think that the problem could be with the I2C communication, the HIGH for Launchpad is 3.3V and could be considered as LOW by the DS1307 ???? Quote Link to post Share on other sites
danigom 2 Posted May 22, 2013 Author Share Posted May 22, 2013 Does it compile? If not, what's the error? Yes, it compiles without any error message, but the Serial Port shows nothing. Quote Link to post Share on other sites
danigom 2 Posted May 22, 2013 Author 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: I get this: The code is: // Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include <Wire.h> #include "RTClib.h" RTC_DS1307 RTC; void setup () { Serial.begin(9600); Wire.begin(); RTC.begin(); if (! RTC.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled RTC.adjust(DateTime(__DATE__, __TIME__)); } } void loop () { DateTime now = RTC.now(); Serial.print("Date: "); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.println(now.day(), DEC); Serial.print("Time: "); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); Serial.println(); delay(3000); } Quote Link to post Share on other sites
cde 334 Posted May 22, 2013 Share Posted May 22, 2013 Does that module have builtin i2c pullup resistors? danigom 1 Quote Link to post Share on other sites
chicken 630 Posted May 22, 2013 Share Posted May 22, 2013 When you press Reset on the LaunchPad, does it display "RTC is not running!"? Also, for better debugging you can try to insert the following lines into your 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); And while looking at the code, I noticed a pretty unusual hack that actually might be a freak cause of the issue: int i = 0; //The new wire library needs to take an int when you are sending for the zero register .. Wire.beginTransmission(0x68); Wire.write(i); Wire.endTransmission(); That's one ugly way to do a cast. AVR being an 8bit might interpret the int as 8 bit, MSP430 will treat it as 16bit. This might confuse the RTC. Try replacing the first line (line 19 in the original library) with uint8_t i = 0; danigom 1 Quote Link to post Share on other sites
danigom 2 Posted May 22, 2013 Author Share Posted May 22, 2013 Does that module have builtin i2c pullup resistors? This is the schematics of the module: Thank you for taking your time. 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.