Jump to content
43oh

Problem with I2C RTC DS1307 Module


Recommended Posts

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

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>  

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

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

Posted Images

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
Link to post
Share on other sites

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!

Link to post
Share on other sites

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
Link to post
Share on other sites

 

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?

Link to post
Share on other sites

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.

Link to post
Share on other sites

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:

 

thump_845008520130522-11.jpg

 

thump_845008120130522-11.jpg

 

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 ???? 

Link to post
Share on other sites

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: 

 

thump_8450208captura2.jpg

 

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);
}
 
Link to post
Share on other sites

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;
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...