Skip to content

Commit 9d20959

Browse files
committed
Implemented setClock for the Due as well
This allows users to change the I2C clock frequency
1 parent f9cdc5e commit 9d20959

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

hardware/arduino/sam/libraries/Wire/Wire.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ TwoWire::TwoWire(Twi *_twi, void(*_beginCb)(void)) :
9696
twi(_twi), rxBufferIndex(0), rxBufferLength(0), txAddress(0),
9797
txBufferLength(0), srvBufferIndex(0), srvBufferLength(0), status(
9898
UNINITIALIZED), onBeginCallback(_beginCb) {
99-
// Empty
99+
setClock(100000); // Set clock frequency to 100000 Hz
100100
}
101101

102102
void TwoWire::begin(void) {
@@ -106,7 +106,7 @@ void TwoWire::begin(void) {
106106
// Disable PDC channel
107107
twi->TWI_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;
108108

109-
TWI_ConfigureMaster(twi, TWI_CLOCK, VARIANT_MCK);
109+
TWI_ConfigureMaster(twi, twiClock, VARIANT_MCK);
110110
status = MASTER_IDLE;
111111
}
112112

@@ -127,6 +127,10 @@ void TwoWire::begin(int address) {
127127
begin((uint8_t) address);
128128
}
129129

130+
void TwoWire::setClock(uint32_t frequency) {
131+
twiClock = frequency;
132+
}
133+
130134
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop) {
131135
if (quantity > BUFFER_LENGTH)
132136
quantity = BUFFER_LENGTH;

hardware/arduino/sam/libraries/Wire/Wire.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TwoWire : public Stream {
3535
void begin();
3636
void begin(uint8_t);
3737
void begin(int);
38+
void setClock(uint32_t);
3839
void beginTransmission(uint8_t);
3940
void beginTransmission(int);
4041
uint8_t endTransmission(void);
@@ -99,7 +100,7 @@ class TwoWire : public Stream {
99100
TwoWireStatus status;
100101

101102
// TWI clock frequency
102-
static const uint32_t TWI_CLOCK = 100000;
103+
uint32_t twiClock;
103104

104105
// Timeouts (
105106
static const uint32_t RECV_TIMEOUT = 100000;

hardware/arduino/sam/libraries/Wire/keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#######################################
1212

1313
begin KEYWORD2
14+
setClock KEYWORD2
1415
beginTransmission KEYWORD2
1516
endTransmission KEYWORD2
1617
requestFrom KEYWORD2

0 commit comments

Comments
 (0)