Jump to content
danigom

Problem with I2C RTC DS1307 Module

Recommended Posts

Hello to everyone, I am new with MSP430 Launchpad and Energ

post-3-0-78441900-1379856453_thumb.jpg

post-3-0-32580500-1379856454_thumb.png

Edited by bluehash
[ADMIN] - Please upload pics to 43oh.com next time

Share this post


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

Share this post


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!

Share this post


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

Share this post


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?

Share this post


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.

Share this post


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

Share this post


Link to post
Share on other sites

Does it compile?

 

If not, what's the error?

 

Yes, it compiles without any error message, but the Serial Port shows nothing. 

 

thump_8450098captura.jpg

Share this post


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);
}
 

Share this post


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;

Share this post


Link to post
Share on other sites

Does that module have builtin i2c pullup resistors?

 

This is the schematics of the module: 

 

thump_8450960captura3.jpg

 

 

Thank you for taking your time. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×