I2C Hilfe/Tutorial

#4129524
Lesenswert?

Hallo Zusammen

Ich möchte mir eine Nixie-Clock bauen, und möchte eine RTC verbauen.

Es handelt sich um die RTC-8564 von EPSON, ich habe diese gewählt weil 
sie bereits "fertig" ist, also man Sie nur noch auflöten muss, der Quarz 
ist schon drinn.  Und Sie ein I2C Interface hat.

Nun ist das Problem, das ich zwar I2C bei Arduino schon öfters verwendet 
habe, jedoch meistens nur mit Libraries.


Kann mir jemand vieleicht erklären / beispiel machen wie ich nun mit dem 
RTC kommunizieren kann?



 Hier das Datenblatt

http://www.xilinx.com/products/boards/ml510/datasheets/765463.pdf
#4129562
Lesenswert?

Johnny SGT schrieb:
> für die RTC DS1307 gibt es eine, aber diese RTC möchte
> ich nicht verwenden, da dort der Quarz noch extern drangelötet werden
> muss.

ich habe die Arduino DS1307new LIB etwas erweitert auf DS3231
http://datasheets.maximintegrated.com/en/ds/DS3231.pdf

bzw. ich teste vorher ob ein DS1307 oder DS3231 am I2C hängt und benutze 
nur die vorhandenen Register.

sie benutzen dieselbe ID die Register für Datum und Uhrzeit liegen auf 
den selben Registern und man kann die DS1307new LIB verwenden.
Es fehlt der DS3231 "nur" der RAM Bereich 56 Byte, kann man also nicht 
nutzen, aber da der Baustein hier teurer ist als fertige Module mit Akku 
bestelle ich die immer in China und diese kommen mit I2C EEPROM.

Der DS3231 braucht auch keinen Quarz, ist eingebaut und er ist auch 
genauer und hat Alarmregister die den µC per /INT auch aus dem 
Tiefschlaf wecken können.
#4129580
Lesenswert?

Joachim B. schrieb:
> Johnny SGT schrieb:
>> für die RTC DS1307 gibt es eine, aber diese RTC möchte
>> ich nicht verwenden, da dort der Quarz noch extern drangelötet werden
>> muss.
>
> ich habe die Arduino DS1307new LIB etwas erweitert auf DS3231
> http://datasheets.maximintegrated.com/en/ds/DS3231.pdf
>
>

Kannst du mir vieleicht sagen wo ich die erweiterte Library finde?

Das IC ist nur ca 1€ Teurer als mein gewähltes und hat eine Standart 
bauform, was mir das basteln eines Eagle-Packages erspart.
#4129829
Lesenswert?

Johnny SGT schrieb:
> Kannst du mir vieleicht sagen wo ich die erweiterte Library finde?

https://code.google.com/p/ds1307new/

für meine "Erweiterung" wäre LIB zuviel gesagt, ich hoffe das hilft :-) 
:
1
#include <avr/io.h>          // (1)
2
#include <Wire.h>
3
#define printIIC(args) Wire.write((uint8_t)args)
4
#define readIIC() Wire.read()
5

6
#include <DS1307new.h>
7
#define DS1307_ID 0x68
8

9
//#if defined(__AVR_ATmega328P__)
10
// ----------------- TON -----------------
11
//#define BEEPER    8 //Pin 7 on LCD -> D11 auf nano
12

13
#if defined(__AVR_ATmega328P__) || defined(M1284P_TIM1)
14
  #define   TIMSKx              TIMSK1
15
  #define   OCIExA              OCIE1A
16
  #define   TIMERx_COMPA_vect   TIMER1_COMPA_vect  // ATmega
17
  #define   TCCRxA              TCCR1A
18
  #define   COMxA0              COM1A0
19
  #define   OCRxA               OCR1A
20
  #define   TCCRxB              TCCR1B
21
  #define   WGMx2               WGM12
22
  #define   CSx0                CS10
23

24
  #define ARDUINO_LED      5
25
  #define DDR_ARDUINO_LED  DDRB
26
  #define PORT_ARDUINO_LED PORTB
27
  #define ARDUINO_LED_ON   PORT_ARDUINO_LED|=(1<<ARDUINO_LED)
28
  #define ARDUINO_LED_OFF  PORT_ARDUINO_LED&=~(1<<ARDUINO_LED)
29
// ----------------- I2C -----------------
30
#define PIN_SDA   4 //PC4 -> A4
31
#define PIN_SCL   5 //PC5 -> A5
32

33
#endif
34

35

36
// --------------------------
37

38
setup()
39
{
40

41
#if (ARDUINO>0)
42
  DEBUG_PRINTLN(F("\nI2C Scanner -> Scanning..."));
43

44
  _i2c_key=0;
45
  byte error, address;
46
  int nDevices=0;
47
  for(address = 1; address < 127; address++ ) 
48
  { // The i2c_scanner uses the return value of
49
    // the Write.endTransmisstion to see if
50
    // a device did acknowledge to the address.
51
    Wire.beginTransmission(address);
52
    error = Wire.endTransmission();
53

54
    if (error == 0)
55
    { DEBUG_PRINT(F("I2C device found at address 0x"));
56
      if (address<16) 
57
        DEBUG_PRINT(F("0"));
58
      DEBUG_PRINT_DEC_HEX(address,HEX);
59
      DEBUG_PRINT(F("; "));
60
      if (address<64) 
61
        DEBUG_PRINT(F("0"));
62
      DEBUG_PRINT_DEC_HEX(address,BIN);
63
      DEBUG_PRINT(F("x; << 0x"));
64
      DEBUG_PRINT_DEC_HEX((address<<1),HEX);
65
      DEBUG_PRINT(F("; "));
66
      if ((address<<1)<128) 
67
        DEBUG_PRINT(F("0"));
68
      DEBUG_PRINT_DEC_HEX((address<<1),BIN);
69
      
70
      switch(address<<1)
71
      {
72
        case 0x40:
73
          i2c_test_flags|=(1<<I2C_TASTATUR);
74
          i2c_test_flags|=(1<<I2C_TASTATUR_8574);
75
          _i2c_key=' ';
76
          DEBUG_PRINTLN(F(" PCF8574  Tastatur"));
77
          break;
78
        case 0x70:
79
          i2c_test_flags|=(1<<I2C_TASTATUR);
80
          i2c_test_flags|=(1<<I2C_TASTATUR_8574A);
81
          _i2c_key='A';
82
          DEBUG_PRINTLN(F(" PCF8574A Tastatur"));
83
          break;
84
        case 0x78:
85
          DEBUG_PRINTLN(F(" I2C OLED         "));
86
          break;
87
        case 0xA0:
88
          DEBUG_PRINTLN(F(" I2C EEPROM       "));
89
          break;
90
        case 0xD0:
91
          Wire.beginTransmission(DS1307_ID);
92
          printIIC(0x3F);
93
          (Wire.endTransmission()) ? i2c_test_flags|=(1<<RTC_3231) : i2c_test_flags|=(1<<RTC_1307);
94
          #ifdef DEBUG
95
          (i2c_test_flags&(1<<RTC_3231)) ? Serial.println(F(" DS3231 RTC ")) : Serial.println(F(" DS1307 RTC "));
96
          #endif
97
          break;
98
        default:
99
          DEBUG_PRINTLN(F(""));
100
          break;
101
      }
102
      nDevices++;
103
    }
104
    else if (error==4) 
105
    { DEBUG_PRINT(F("Unknow error at address 0x"));
106
      if (address<16) 
107
        DEBUG_PRINT(F("0"));
108
      DEBUG_PRINTLN_DEC_HEX(address,HEX);
109
    }    
110
  }
111
  if (nDevices == 0)
112
    DEBUG_PRINTLN(F("No I2C devices found\n"));
113
  else
114
    DEBUG_PRINTLN(F("done\n"));
115
  DEBUG_PRINTLN(F(""));
116
#else
117
  test_i2c_key();
118
#endif
119
}
120

121
//--------------------------------------------------------------
122

123
// ---- time ----
124
  _i2c_busy=1; RTC.getTime(); _i2c_busy=0;  
125
  sprintf(r_time_str,"%02d:%02d:%02d", RTC.hour, RTC.minute, RTC.second);
126
  myGLCD.print(r_time_str, LEFT, 27);
127
  myGLCD.print("RTC", (9*6), 27);
128
  sprintf(r_date_str,"%04d/%02d/%02d", RTC.year, RTC.month, RTC.day);
129
  myGLCD.print(r_date_str, LEFT, 36);
130

131

132
// ---- temp ----
133
    if( i2c_test_flags&(1<<RTC_3231) ) 
134
//    { if( !last_temp_clk || (RTC.time2000 > (last_temp_clk+10)) )
135
    { if(RTC.second%30 == 0)
136
      {  myGLCD.print("              ", LEFT, 9); myGLCD.print("Temp ", LEFT, 9); myGLCD.print(temperatur_str_rtc(-3), (4*6), 9);
137
      }
138
      else
139
        if( !(RTC.second%5) && (i2c_test_flags&(1<<RTC_TEMP_RD_SET)) )
140
          i2c_test_flags&=~(1<<RTC_TEMP_RD_SET); 
141

142
      if(i2c_test_flags&(1<<RTC_TEMP_RD_SET))
143
        myGLCD.print("up", (12*6), 9);
144
      else
145
        myGLCD.print("  ", (12*6), 9);
146
    }

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren