Softi2c with pull up enabled
Revision 2:7e8f03569953, committed 2019-05-29
- Comitter:
- wkleunen
- Date:
- Wed May 29 06:37:22 2019 +0000
- Parent:
- 1:05473196d133
- Commit message:
- Enable pull up on softi2c
Changed in this revision
SoftI2C.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 05473196d133 -r 7e8f03569953 SoftI2C.cpp --- a/SoftI2C.cpp Mon Nov 28 19:55:30 2016 +0000 +++ b/SoftI2C.cpp Wed May 29 06:37:22 2019 +0000 @@ -2,10 +2,11 @@ SoftI2C::SoftI2C(PinName sda, PinName scl) : _sda(sda), _scl(scl) { // Set defaults - _sda.mode(PullNone); - _scl.mode(PullNone); _sda.input(); _scl.input(); + _sda.mode(PullUp); + _scl.mode(PullUp); + frequency(100000); active = false; @@ -106,6 +107,7 @@ //Change SDA depending on the bit if ( (data >> i) & 0x01 ) { _sda.input(); + _sda.mode(PullUp); } else { _sda.output(); _sda.write(0); @@ -122,6 +124,7 @@ wait_us(delay_us); _sda.input(); + _sda.mode(PullUp); wait_us(delay_us); _scl.write(1); @@ -136,6 +139,7 @@ if (active) { //if repeated start //Set SDA high, toggle scl _sda.input(); + _sda.mode(PullUp); _scl.output(); _scl.write(0); wait_us(delay_us << 1); @@ -157,8 +161,10 @@ _sda.write(0); wait_us(delay_us); _scl.input(); + _scl.mode(PullUp); wait_us(delay_us); _sda.input(); + _sda.mode(PullUp); wait_us(delay_us); active = false;