PCF 8583 & arduino
- Войдите на сайт для отправки комментариев
Пт, 17/02/2012 - 18:54
Пытаюсь завести RTClock плату от Микроэлектроники с помощью Arduino
Соединил через самодельный шилд питание, землю, клок на А5 и данные на А4.
Прерывание никуда.
Програмка пример с ардуино сайта (serial.begin() пришлось добавить, не работало на порт):
#include <Wire.h>
#include <Rtc_Pcf8563.h>
//init the real time clock
Rtc_Pcf8563 rtc;
void setup()
{
Serial.begin(9600);
//clear out the registers
rtc.initClock();
//set a time to start with.
//day, weekday, month, century(1=1900, 0=2000), year(0-99)
rtc.setDate(14, 6, 3, 1, 10);
//hr, min, sec
rtc.setTime(1, 15, 0);
}
void loop()
{
//both format functions call the internal getTime() so that the
//formatted strings are at the current time/date.
Serial.print(rtc.formatTime());
Serial.print("\r\n");
Serial.print(rtc.formatDate());
Serial.print("\r\n");
delay(1000);
}
Вот только не заводится..
00/00/2000
00:00:00
00/00/2000
00:00:00
00/00/2000
00:00:00
00/00/2000
00:00:00
00/00/2000
00:00:00
00/00/2000
Вот такое гонит на ком порту и все.
Как бы поотлаживать? Что не так?
Вот такой вот у меня шилд получился из двух плат от Микроэлектроники.
LCD нормально работает а вот часики не стартуют.
Вот ведь дрянь, какая! Часы пошли, но с другой библиотекой.
#include <Wire.h> // necessary, or the application won't build properly #include <stdio.h> #include <PCF8583.h> /***************************************************************************** * read/write serial interface to PCF8583 RTC via I2C interface * * Arduino analog input 5 - I2C SCL (PCF8583 pin 6) * Arduino analog input 4 - I2C SDA (PCF8583 pin 5) * * You can set the type by sending it YYMMddhhmmss; * the semicolon on the end tells it you're done... * ******************************************************************************/ int correct_address = 0; PCF8583 p (0xA0); void setup(void){ Serial.begin(9600); Serial.print("booting..."); Serial.println(" done"); } void loop(void){ if(Serial.available() > 0){ p.year= (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)) + 2000; p.month = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); p.day = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); p.hour = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); p.minute = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48)); p.second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48)); // Use of (byte) type casting and ascii math to achieve result. if(Serial.read() == ';'){ Serial.println("setting date"); p.set_time(); } } p.get_time(); char time[50]; sprintf(time, "%02d/%02d/%02d %02d:%02d:%02d", p.year, p.month, p.day, p.hour, p.minute, p.second); Serial.println(time); delay(3000); }Это на мониторе:
-16385/01/30 20:02:05
-16385/01/30 20:02:08
-16385/01/30 20:02:11
-16385/01/30 20:02:14
-16385/01/30 20:02:17
-16385/01/30 20:02:20
-16385/01/30 20:02:23
-16385/01/30 20:02:26
-16385/01/30 20:02:29
-16385/01/30 20:02:32
-16385/01/30 20:02:35
-16385/01/30 20:02:38
-16385/01/30 20:02:41
-16385/01/30 20:02:45
-16385/01/30 20:02:48
Еще есть грязь, но самое главное идут!
Вроде выставил дату, вот только почему то 2000 не добавляется к году:
0012/02/17 20:35:21
0012/02/17 20:35:22
0012/02/17 20:35:23
0012/02/17 20:35:24
0012/02/17 20:35:25
0012/02/17 20:35:26
0012/02/17 20:35:27
0012/02/17 20:35:28
0012/02/17 20:35:29
0012/02/17 20:35:30
Кто скажет почему, где помарка?
Типа даже получилось:
#include <Wire.h> // necessary, or the application won't build properly
#include <stdio.h>
#include <LiquidCrystal.h>
#include <PCF8583.h>
int correct_address = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
PCF8583 p (0xA0);
void setup(void){
Serial.begin(9600);
Serial.print("booting...");
Serial.println(" done");
/* Инициализируем дисплей: 2 строки по 16 символов */
lcd.begin(16, 2);
}
void loop(void){
if(Serial.available() > 0){
p.year= (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48) + 2000);
p.month = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
p.day = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
p.hour = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
p.minute = (byte) ((Serial.read() - 48) *10 + (Serial.read() - 48));
// Use of (byte) type casting and ascii math to achieve result.
p.second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48));
if(Serial.read() == ';'){
Serial.println("setting date");
p.set_time();
}
}
p.get_time();
char time1[10], time2[10];
sprintf(time1, "%02d/%02d/%02d", p.year, p.month, p.day);
sprintf(time2, "%02d:%02d:%02d", p.hour, p.minute, p.second);
Serial.println(time2);
lcd.setCursor(0, 0);
lcd.print(time1);
lcd.setCursor(0, 1);
lcd.print(time2);
delay(990);
}