-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds2401.h
100 lines (84 loc) · 2.38 KB
/
ds2401.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* File: ds2401.h
* Author: SD
*
* Created on 24 février 2020, 18:08
*
* https://datasheets.maximintegrated.com/en/ds/DS2401.pdf
* Voir programme d'exemple en bas de ce fichier
*/
#include "oneWire.h"
#ifndef DS2401_H
#define DS2401_H
#ifdef __cplusplus
extern "C" {
#endif
#define DS2401_MEMORY_SIZE 8
#define DS2401_READ_ROM 0x33
#define DS2401_FAMILLY_CODE 0x01
/**
* Initialise la GPIO DQ du bus OneWire. Fait un reset du bus OneWire,
* si un périphérique est connecté, il doit répondre
*
* @author SD
* @return TRUE ou FALSE selon si un périphérique à répondu ou pas
*/
owByte ow_DS2401_init();
/**
* Lit la mémoire interne du DS2401
* @author SD
*
* @param owRom : pointeur sur un tableau de 8 octets :
* - octet 1 : Familly code : 01h
* - octets 2 à 7 : Identifiant unique 48 bits (MSB first)
* - octet 8 : CRC code
*
* @return TRUE si un périphérique répond et si le "familly code" correspond à 01h
*/
owByte ow_DS2401_getID(owByte* owRom);
/**
* Convertit l'identifiant unique 48 bits en une chaine de caractères
* @author SD
*
* @param owRom : pointeur sur un tableau de 8 octets :
* - octet 1 : Familly code : 01h
* - octets 2 à 7 : Identifiant unique 48 bits (LSB first)
* - octet 8 : CRC code
* @param strID : pointeur sur un tableau de caractères qui contiendra le
* résultat. Le tableau doit avoir une taille d'au moins 13 caractères
*/
void owDS2401_ID_To_String(owByte* owRom, char* strID);
/**
* Usage interne seulement
* Convertit un un nombre entier non signé [0 - 15] en un caractère hexadécimal
* @param number : nombre compris entre 0 et 15
* @return : caractère hexadécimal correspondant à number
*/
char _numberToHex(owByte number);
/* // Programme d'exemple d'utilisation (main)
#include "mcc_generated_files/mcc.h"
#include "ds2401.h"
void main(void)
{
// initialize the device
SYSTEM_Initialize();
owByte owRom[DS2401_MEMORY_SIZE];
if(ow_DS2401_init()) {
if(ow_DS2401_getID(owRom)) {
char str[13];
owDS2401_ID_To_String(owRom, str);
printf("ID : %s\r\n",str);
}
else {
printf("ERREUR, \"Familly code\" invalide ou CRC invalide\r\n");
}
}
else {
printf("ERREUR, périphérique OneWire non détecté ou ne répond pas\r\n");
}
}
*/
#ifdef __cplusplus
}
#endif
#endif /* DS2401_H */