LCDDriver_NXP_Arduino 0.2.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
8{
9}
10
11void M24C02::begin( void )
12{
13}
14
15int M24C02::write( int byte_adr, uint8_t data )
16{
17 if ( !wait_write_complete( 10 ) )
18 return -10;
19
20 int r = reg_w( byte_adr, data );
21
22 if ( !wait_write_complete( 10 ) )
23 return -10;
24
25 return r;
26}
27
28int M24C02::write( int byte_adr, uint8_t *dp, int length )
29{
30#define PAGE_WRITE_SIZE 16
31 int w_size;
32 int written = 0;
33
34 while ( length ) {
35 w_size = ( PAGE_WRITE_SIZE < length ) ? PAGE_WRITE_SIZE : length;
36
37 if ( !wait_write_complete( 10 ) )
38 return -10;
39
40 w_size = reg_w( byte_adr, dp, w_size ) - 1;
41
42 if ( w_size < 0 )
43 return w_size;
44
45 length -= w_size;
46 written += w_size;
47 byte_adr += w_size;
48 dp += w_size;
49 }
50
51 if ( !wait_write_complete( 10 ) )
52 return -10;
53
54 return written;
55}
56
58{
59 while ( !ping() && n-- )
60 delay( 1 );
61
62 if ( !n )
63 Serial.println("time out in M24C02::wait_write_complete()");
64
65 return n;
66}
67
68uint8_t M24C02::read( int byte_adr )
69{
70 return reg_r( byte_adr );
71}
72
73int M24C02::read( int byte_adr, uint8_t *dp, int length )
74{
75#define PAGE_READ_SIZE 32
76 int r_size;
77 int read_done = 0;
78
79 while ( length ) {
80 r_size = ( PAGE_READ_SIZE < length ) ? PAGE_READ_SIZE : length;
81
82 r_size = reg_r( byte_adr, dp, r_size );
83
84 length -= r_size;
85 read_done += r_size;
86 byte_adr += r_size;
87 dp += r_size;
88 }
89
90 return read_done;
91}
92
#define PAGE_WRITE_SIZE
#define PAGE_READ_SIZE
int wait_write_complete(int n)
Definition: M24C02.cpp:57
uint8_t read(int byte_adr)
Definition: M24C02.cpp:68
void begin(void)
Definition: M24C02.cpp:11
virtual ~M24C02()
Definition: M24C02.cpp:7
M24C02(uint8_t i2c_address=(0xA0 > > 1))
Definition: M24C02.cpp:3
int write(int byte_adr, uint8_t data)
Definition: M24C02.cpp:15