Browse Source

Add Wire.end()

main
PaulStoffregen 8 years ago
parent
commit
37f7d78693
2 changed files with 18 additions and 0 deletions
  1. +16
    -0
      Wire.cpp
  2. +2
    -0
      Wire.h

+ 16
- 0
Wire.cpp View File

@@ -167,6 +167,15 @@ void TwoWire::begin(uint8_t address)
NVIC_ENABLE_IRQ(IRQ_I2C0);
}

void TwoWire::end()
{
NVIC_DISABLE_IRQ(IRQ_I2C0);
I2C0_C1 = 0;
CORE_PIN18_CONFIG = 0;
CORE_PIN19_CONFIG = 0;
SIM_SCGC4 &= ~SIM_SCGC4_I2C0; // TODO: use bitband
}

void i2c0_isr(void)
{
uint8_t status, c1, data;
@@ -628,6 +637,13 @@ void TwoWire::begin(int address)
begin((uint8_t)address);
}

void TwoWire::end()
{
TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA));
digitalWrite(SDA, 0);
digitalWrite(SCL, 0);
}

void TwoWire::setClock(uint32_t frequency)
{
TWBR = ((F_CPU / frequency) - 16) / 2;

+ 2
- 0
Wire.h View File

@@ -26,6 +26,7 @@
#include "Arduino.h"

#define BUFFER_LENGTH 32
#define WIRE_HAS_END 1

extern "C" void i2c0_isr(void);

@@ -53,6 +54,7 @@ class TwoWire : public Stream
void begin();
void begin(uint8_t);
void begin(int);
void end();
void setClock(uint32_t);
void beginTransmission(uint8_t);
void beginTransmission(int);

Loading…
Cancel
Save