LCDDriver_NXP_Arduino 0.3.0
Temperature sensor device operation sample code for Arduino
Loading...
Searching...
No Matches
M24C02.cpp
Go to the documentation of this file.
1#include <M24C02.h>
2
3M24C02::M24C02( uint8_t i2c_address ) : I2C_device( i2c_address )
4{
5}
6
7M24C02::M24C02( TwoWire& wire, uint8_t i2c_address ) : I2C_device( wire, i2c_address )
8{
9}
10
12{
13}
14
15void M24C02::begin( void )
16{
17}
18
19int M24C02::write( int byte_adr, uint8_t data )
20{
21 if ( !wait_write_complete( 10 ) )
22 return -10;
23
24 int r = reg_w( byte_adr, data );
25
26 if ( !wait_write_complete( 10 ) )
27 return -10;
28
29 return r;
30}
31
32int M24C02::write( int byte_adr, uint8_t *dp, int length )
33{
34#define PAGE_WRITE_SIZE 16
35 int w_size;
36 int written = 0;
37
38 while ( length ) {
39 w_size = ( PAGE_WRITE_SIZE < length ) ? PAGE_WRITE_SIZE : length;
40
41 if ( !wait_write_complete( 10 ) )
42 return -10;
43
44 w_size = reg_w( byte_adr, dp, w_size ) - 1;
45
46 if ( w_size < 0 )
47 return w_size;
48
49 length -= w_size;
50 written += w_size;
51 byte_adr += w_size;
52 dp += w_size;
53 }
54
55 if ( !wait_write_complete( 10 ) )
56 return -10;
57
58 return written;
59}
60
62{
63 while ( !ping() && n-- )
64 delay( 1 );
65
66 if ( !n )
67 Serial.println("time out in M24C02::wait_write_complete()");
68
69 return n;
70}
71
72uint8_t M24C02::read( int byte_adr )
73{
74 return reg_r( byte_adr );
75}
76
77int M24C02::read( int byte_adr, uint8_t *dp, int length )
78{
79#define PAGE_READ_SIZE 32
80 int r_size;
81 int read_done = 0;
82
83 while ( length ) {
84 r_size = ( PAGE_READ_SIZE < length ) ? PAGE_READ_SIZE : length;
85
86 r_size = reg_r( byte_adr, dp, r_size );
87
88 length -= r_size;
89 read_done += r_size;
90 byte_adr += r_size;
91 dp += r_size;
92 }
93
94 return read_done;
95}
96
#define PAGE_WRITE_SIZE
#define PAGE_READ_SIZE
int wait_write_complete(int n)
Definition: M24C02.cpp:61
uint8_t read(int byte_adr)
Definition: M24C02.cpp:72
void begin(void)
Definition: M24C02.cpp:15
virtual ~M24C02()
Definition: M24C02.cpp:11
M24C02(uint8_t i2c_address=(0xA0 > > 1))
Definition: M24C02.cpp:3
int write(int byte_adr, uint8_t data)
Definition: M24C02.cpp:19