Coucou Jean-Marie.
J’ai testé le DS1337 avec l’IDE Arduino / ESP8266.
J’ai juste mis une led sur la sortie Alarme2 (INTB) du ds1337.
J’ai un problème car le registre des statuts m’indique que le l’oscillator est arrêté (OSF=Bit 7 du registre Status en 0x0F).
Je n’ai pas de quartz à 32.768KHZ, j’ai mis un quartz de 31.400KHZ.
Les secondes ne sont pas incrémentées (ou très lentement).
Les raison évoquées par la doc du DS1337 sont :
Code : Tout sélectionner
Bit 7: Oscillator Stop Flag (OSF). A logic 1 in this bit indicates that the oscillator either is stopped or was stopped for some period of time and may be used to judge the validity of the clock and calendar data. This bit is set to logic 1 anytime that the oscillator stops. The following are examples of conditions that can cause the OSF bit to be set:
1) The first time power is applied.
2) The voltage present on VCC is insufficient to support oscillation.
3) The EOSC bit is turned off.
4) External influences on the crystal (e.g., noise, leakage, etc.).
J’ai pensé à un PB de perturbation en WiFI.
Je n’ai pas trouvé de solution pour arrêter l’émission wifi avec l’IDE Arduino /ESP8266.
J’ai essayé avec Lua idem , oscillator à l’arrêt.
Si j’enlève le Quartz j’ai exactement les mêmes résultats.
J’ai commandé un quartz à 32.768KHZ pour voir si le PB vient du Quartz.
Attention, Il faut couper l'alimentation du DS1337 un certain temps pour que celui ci reprenne ses valeurs par défaut.
Voici le code de l’IDE Arduino / ESP8266
.
Il doit fonctionner avec un Arduino en modifiant la vitesse de l’UART et en indiquant correctement les GPIO.
Remplacer Wire.pins(2, 14);
Il faut également supprimer #include <ESP8266WiFi.h>
Code : Tout sélectionner
#include "Wire.h"
#include <ESP8266WiFi.h>
#define DS1337_I2C_ADDRESS 0x68 // the I2C address of RTC
// Convert normal decimal numbers to binary coded decimal
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) );
}
// Ininialisation registres date= adr 0x-00 -> Ox06, alarme1 = 0x07 -> 0x0a, alarme2= 0x0b -> 0x0d
// Contrôles =0x0E
void setDataDs1337(byte adr, int lg,byte buff[])
{
int i;
Wire.beginTransmission(DS1337_I2C_ADDRESS);
Wire.write(adr);
for (i= 0 ;i< lg;i++){Wire.write(buff[i]); }
Wire.endTransmission();
}
void StatusDs1337() // lecture controles et status
{
byte controle,status;
Wire.beginTransmission(DS1337_I2C_ADDRESS);
Wire.write(0x0E);
Wire.endTransmission();
Wire.requestFrom(DS1337_I2C_ADDRESS, 2);
controle=Wire.read();
status=Wire.read();
Serial.print("Controles=");
Serial.print(controle, HEX); // control
Serial.print(", Status=");
Serial.print(status, HEX); // status
Serial.print(", Date=");
}
// lectures registre et affichage en hexa est bcd
void getDataHexDs1337(const char libelle[],byte adr, int lg)
{
int i;
byte oct;
Serial.print(libelle);
Serial.print(" adr=");Serial.print(adr, HEX);
Wire.beginTransmission(DS1337_I2C_ADDRESS);
Wire.write(adr); Serial.print("->");
Wire.endTransmission();
Wire.requestFrom(DS1337_I2C_ADDRESS, lg);
for (i= 0 ;i< lg;i++)
{
oct=Wire.read();
Serial.print(" (");
Serial.print(oct, HEX);
Serial.print("):");
Serial.print( bcdToDec(oct & 0x7F), DEC); // 12/24 et AM/PM et DY/DT (Date of month) toujours à 0
}
Serial.println(" ");
Wire.endTransmission();
}
// Lecture et affichage date en cours
void getDateDs1337()
{
byte second, minute, hour, dayOfWeek,dayOfMonth, month, year;
// Reset the register pointer
Wire.beginTransmission(DS1337_I2C_ADDRESS);
Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS1337_I2C_ADDRESS, 7);
second = bcdToDec(Wire.read() & 0x7f); // sauf bit 7
minute = bcdToDec(Wire.read());
//hour = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm
hour = bcdToDec(Wire.read() );
dayOfWeek = bcdToDec(Wire.read());
dayOfMonth = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(" ");
Serial.println();
//Serial.print("Day of week:");
}
void setup() {
byte A1M1,A1M2,A1M3,A1M4,DYDT1,A2M1,A2M2,A2M3,A2M4,DYDT2,AMPM1224;
byte second, minute, hour, dayOfWeek,dayOfMonth, month, year;
Wire.pins(2, 14); // sur esp8266= gpio2 et GPIO14
Wire.begin();
Serial.begin(115200);
delay(5000);
// alarmes
A1M1=0x80;
A1M2=0x80;
A1M3=0x80;
A1M4=0x80;
DYDT1=0x00;
A2M2=0x80;
A2M3=0x80;
A2M4=0x80;
DYDT2=0x00;
AMPM1224 = 0x00; // 24H et date du mois
second = decToBcd(0);
minute = decToBcd(23);
hour = decToBcd(22);
dayOfWeek = decToBcd(7);
dayOfMonth = decToBcd(1);
month = decToBcd(5);
year = decToBcd(15);
Serial.println("valeurs initiales");
StatusDs1337(); // lecture et affichage valeurs initilales contrôles et status
Serial.println();
byte tb_date[]={second,minute,hour,dayOfWeek,dayOfMonth,month,year};
setDataDs1337(0x00,sizeof(tb_date),tb_date); // Maj date en 0x00
getDataHexDs1337("lecture date",0x00,7);
byte tb_alarme1[]={(byte)(second| A1M1),(byte)(minute|A1M2),(byte)(hour| A1M3|AMPM1224),(byte)(dayOfMonth| A1M4 | DYDT1)};
setDataDs1337(0x07,sizeof(tb_alarme1),tb_alarme1); // maj alarme1 en 0x07
getDataHexDs1337("Alarme1",0x07,4);
byte tb_alarme2[]={(byte)(minute |A1M2),(byte)(hour| A1M3|AMPM1224),byte(dayOfMonth | A1M4 | DYDT1)};
setDataDs1337(0x0B,sizeof(tb_alarme2),tb_alarme2); // maj alarme2 en 0xOB
getDataHexDs1337("Alarme2",0x0B,3);
byte controle[]={(byte)0x00};
//setDataDs1337(0x0E,1,controle); // maj byte contrôles en 0x0e
}
void loop()
{
delay(2000);
StatusDs1337 (); // lecture controles et status
getDateDs1337(); //lecture date
}
Et voici la trace
Code : Tout sélectionner
valeurs initiales
Controles=18, Status=83, Date=
lecture date adr=0-> (0):0 (23):23 (22):22 (7):7 (1):1 (5):5 (15):15
Alarme1 adr=7-> (80):0 (A3):23 (A2):22 (81):1
Alarme2 adr=B-> (A3):23 (A2):22 (81):1
Controles=18, Status=83, Date=22:23:0 5/1/15
Controles=18, Status=83, Date=22:23:0 5/1/15
Controles=18, Status=83, Date=22:23:0 5/1/15
Controles=18, Status=83, Date=22:23:0 5/1/15
Controles=18, Status=83, Date=22:23:0 5/1/15
Controles=18, Status=83, Date=22:23:1 5/1/15
Controles=18, Status=83, Date=22:23:1 5/1/15
Controles=18, Status=83, Date=22:23:1 5/1/15
Controles=18, Status=83, Date=22:23:1 5/1/15
Controles=18, Status=83, Date=22:23:2 5/1/15
Le programme en Lua
Code : Tout sélectionner
id=0
sda=4
scl=5
function test_i2c()
for i=0,127 do
i2c.start(id)
resCode = i2c.address(id, i, i2c.TRANSMITTER)
i2c.stop(id)
if resCode == true then print("adresse trouvée " .. string.format("%02x", i) .. " (" .. i ..")") end
end
end
function read_reg(dev_addr, reg_addr)
i2c.start(id)
i2c.address(id, 0x68 ,i2c.TRANSMITTER)
i2c.write(id,reg_addr)
i2c.stop(id)
i2c.start(id)
i2c.address(id, 0x68,i2c.RECEIVER)
c=i2c.read(id,1)
i2c.stop(id)
return c
end
function ecr_registres(dev_addr, reg_addr,liste)
i2c.start(id)
i2c.address(id, dev_addr ,i2c.TRANSMITTER)
i2c.write(id,reg_addr)
c=i2c.write(id,liste)
i2c.stop(id)
end
function lect_registres (dev_adr,adr,lg)
txt=""
for i =adr,adr+lg-1 do
txt=txt .. string.format("%02x",string.byte(read_reg(dev_adr,i),1)) .. " "
end
print(txt)
end
-- main
realtype = wifi.sleeptype(wifi.MODEM_SLEEP) -- arret wifi
node.dsleep(nil, 4)
i2c.setup(id,sda,scl,i2c.SLOW) -- initialisation i2c
test_i2c() --recherche adresse i2c")
print("valeurs initiales")
print("<-------date----------><--alarm1-><alarm2>C0 ST")
lect_registres(0x68,0x00,16)
ecr_registres(0x68,0x00,{0,1,2,3,4,5,6}) -- ecriture registres date en 0x00
ecr_registres(0x68,0x07,{0x00,0x00,0x00,0x00}) -- raz registres alarme1 en 0x07
ecr_registres(0x68,0x0B,{0x80,0x81,0x83}) -- ecriture registres alarme2 en 0x0B
-- ecr_registres(0x68,0x0E,{0}) -- ecriture controle en 0x0E
-- ecr_registres(0x68,0x0E,{0x08}) -- ecriture controle en 0x0E led clignote
lect_registres(0x68,0x00,16)
print("")
tmr.alarm(0,10000, 1, function() lect_registres(0x68,0x00,16) end ) --lectures registres
Et la trace en Lua
Code : Tout sélectionner
dofile("lectI2C.lua")
adresse trouvée 68 (104)
valeurs initiales
<-------date----------><--alarm1-><alarm2>C0 ST
00 00 00 01 01 01 00 00 00 00 00 00 00 00 18 81
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
00 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
01 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
01 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
01 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
01 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
01 01 02 03 04 05 06 00 00 00 00 80 81 83 18 83
Pour les transistors, j'ai commandé des 2N7000 , je ne me rappelle plus pourquoi j'ai commandé ce modèle ?.
A+
SMBA38.