Implemented setClock for the Due as well

This allows users to change the I2C clock frequency
This commit is contained in:
Kristian Lauszus 2014-07-02 19:47:23 +02:00
parent f9cdc5ea00
commit 9d20959b6a
3 changed files with 9 additions and 3 deletions

View File

@ -96,7 +96,7 @@ TwoWire::TwoWire(Twi *_twi, void(*_beginCb)(void)) :
twi(_twi), rxBufferIndex(0), rxBufferLength(0), txAddress(0),
txBufferLength(0), srvBufferIndex(0), srvBufferLength(0), status(
UNINITIALIZED), onBeginCallback(_beginCb) {
// Empty
setClock(100000); // Set clock frequency to 100000 Hz
}
void TwoWire::begin(void) {
@ -106,7 +106,7 @@ void TwoWire::begin(void) {
// Disable PDC channel
twi->TWI_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
TWI_ConfigureMaster(twi, TWI_CLOCK, VARIANT_MCK);
TWI_ConfigureMaster(twi, twiClock, VARIANT_MCK);
status = MASTER_IDLE;
}
@ -127,6 +127,10 @@ void TwoWire::begin(int address) {
begin((uint8_t) address);
}
void TwoWire::setClock(uint32_t frequency) {
twiClock = frequency;
}
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) {
if (quantity > BUFFER_LENGTH)
quantity = BUFFER_LENGTH;

View File

@ -35,6 +35,7 @@ public:
void begin();
void begin(uint8_t);
void begin(int);
void setClock(uint32_t);
void beginTransmission(uint8_t);
void beginTransmission(int);
uint8_t endTransmission(void);
@ -99,7 +100,7 @@ private:
TwoWireStatus status;
// TWI clock frequency
static const uint32_t TWI_CLOCK = 100000;
uint32_t twiClock;
// Timeouts (
static const uint32_t RECV_TIMEOUT = 100000;

View File

@ -11,6 +11,7 @@
#######################################
begin KEYWORD2
setClock KEYWORD2
beginTransmission KEYWORD2
endTransmission KEYWORD2
requestFrom KEYWORD2