-
Notifications
You must be signed in to change notification settings - Fork 4
/
twi_ow_functions.c
121 lines (103 loc) · 2.69 KB
/
twi_ow_functions.c
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
Licensed under the EUPL V.1.1, Lizenziert unter EUPL V.1.1
*/
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include "twi_master.h"
#include "twi_ow_functions.h"
void Twim_Owi_Single_Bit_High(uint8_t Device)
{
uint8_t status = 0;
twi_data[0] = TWI_OWI_OW_SINGLE_BIT;
twi_data[1] = TWI_OWI_BIT_BYTE_HIGH;
twi_bytes_to_transceive = 2;
status = Twim_Write_Data(Device, twi_bytes_to_transceive, twi_data);
if ( TWI_success != status )
{
TWI_errorAnalysis(status);
}
}
void Twim_Owi_Single_Bit_Low(uint8_t Device)
{
uint8_t status = 0;
twi_data[0] = TWI_OWI_OW_SINGLE_BIT;
twi_data[1] = TWI_OWI_BIT_BYTE_LOW;
twi_bytes_to_transceive = 2;
status = Twim_Write_Data(Device, twi_bytes_to_transceive, twi_data);
if ( TWI_success != status )
{
TWI_errorAnalysis(status);
}
}
void Twim_Owi_Reset_Device(uint8_t Device)
{
uint8_t status = 0;
twi_data[0] = TWI_OWI_DEVICE_RESET;
twi_bytes_to_transceive = 1;
status = Twim_Write_Data(Device, twi_bytes_to_transceive, twi_data);
if ( TWI_success != status )
{
TWI_errorAnalysis(status);
}
}
uint8_t Twim_Owi_Set_Configuration(uint8_t Device, uint8_t configuration_nibble)
{
uint8_t status = 0;
twi_data[0] = TWI_OWI_WRITE_CONFIGURATION;
twi_data[1] = configuration_nibble | (((~configuration_nibble)&0x0F)<<4); // upper nibble has to be the one's complement of the lower nibble
twi_bytes_to_transceive = 2;
status = Twim_Write_Data(Device, twi_bytes_to_transceive, twi_data);
if ( TWI_success != status )
{
TWI_errorAnalysis(status);
}
// Read back the configuration register to validate writing process
twi_bytes_to_transceive = 1;
status = Twim_Read_Data(Device, twi_bytes_to_transceive, twi_data);
if ( TWI_success != status )
{
TWI_errorAnalysis(status);
}
if(twi_data[0] != configuration_nibble)
{
return FALSE;
}
else {
return TRUE;
}
}
void Twim_Owi_Read_Status(uint8_t Device)
{
uint8_t status = 0;
twi_bytes_to_transceive = 2;
twi_data[0] = TWI_OWI_SET_READ_POINTER;
twi_data[1] = TWI_OWI_STATUS_REGISTER;
status = Twim_Write_Data(Device, twi_bytes_to_transceive, twi_data);
if ( TWI_success != status )
{
TWI_errorAnalysis(status);
}
twi_bytes_to_transceive = 1;
status = Twim_Read_Data(Device, twi_bytes_to_transceive, twi_data);
if ( TWI_success != status )
{
TWI_errorAnalysis(status);
}
}
void Twim_Owi_Ow_Reset(uint8_t Device)
{
uint8_t status = 0;
twi_bytes_to_transceive = 1;
twi_data[0] = TWI_OWI_OW_RESET;
status = Twim_Write_Data(Device, twi_bytes_to_transceive, twi_data);
if ( TWI_success != status )
{
TWI_errorAnalysis(status);
}
}
uint8_t Twim_Owi_Busy_Return(uint8_t Device)
{
Twim_Owi_Read_Status(Device);
return (twi_data[0] & 0x01); // return busy flag, 1 == busy
}