Jump to content
43oh

Problem with I2C RTC DS1307 Module


Recommended Posts

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:

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

 

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.

Link to post
Share on other sites

Don't give up yet, we haven't even identified the actual issue :smile:

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 :smile:

 

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

Link to post
Share on other sites

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.

Link to post
Share on other sites

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.

Link to post
Share on other sites

Don't give up yet, we haven't even identified the actual issue :smile:

 

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 :smile:

 

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

 

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: 

thump_8452742sin-ttulo.jpg

 

But when I supply the module with 3.3V I get this (something curious happens):

thump_8450208captura2.jpg

 

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: 

 

thump_8452756sin-ttulo22.jpg

 

I think this demonstrates that the module is incompatible. Isn't it? 

Link to post
Share on other sites

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

Link to post
Share on other sites
  • 3 months later...

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