My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
/*
* SoftI2CMaster.h -- Multi-instance software I2C Master library
*
* 2010-2012 Tod E. Kurt, http://todbot.com/blog/
*
*/

#ifndef SoftI2CMaster_h
#define SoftI2CMaster_h

#include <inttypes.h>

#define _SOFTI2CMASTER_VERSION 12 // software version of this library


class SoftI2CMaster
{

private:
// per object data
uint8_t _sdaPin;
uint8_t _sclPin;
uint8_t _sdaBitMask;
uint8_t _sclBitMask;
volatile uint8_t *_sdaPortReg;
volatile uint8_t *_sclPortReg;
volatile uint8_t *_sdaDirReg;
volatile uint8_t *_sclDirReg;

boolean usePullups;

// private methods
void setPins(uint8_t sdaPin, uint8_t sclPin, boolean usePullups);

void i2c_writebit( uint8_t c );
uint8_t i2c_readbit(void);
void i2c_init(void);
void i2c_start(void);
void i2c_repstart(void);
void i2c_stop(void);
uint8_t i2c_write( uint8_t c );
uint8_t i2c_read( uint8_t ack );

public:
// public methods
SoftI2CMaster(uint8_t sdaPin, uint8_t sclPin);
SoftI2CMaster(uint8_t sdaPin, uint8_t sclPin, boolean usePullups);

uint8_t beginTransmission(uint8_t address);
uint8_t beginTransmission(int address);
uint8_t endTransmission(void);
uint8_t send(uint8_t);
void send(uint8_t*, uint8_t);
void send(int);
void send(char*);

uint8_t requestFrom(int address);
uint8_t requestFrom(uint8_t address);
uint8_t receive( uint8_t ack );
uint8_t receive();
uint8_t receiveLast();

};

#endif

Change log

r125 by tod.kurt on Jan 18, 2012   Diff
SoftI2cMaster now supports tunable pull-up
resistors
Go to: 
Project members, sign in to write a code review

Older revisions

r123 by tod.kurt on Jan 18, 2012   Diff
SoftI2CMaster now supports reads and
writes
r62 by tod.kurt on Sep 24, 2010   Diff
small cleanup
r59 by tod.kurt on Sep 24, 2010   Diff
added soft i2c demo
All revisions of this file

File info

Size: 1485 bytes, 65 lines
Powered by Google Project Hosting