Skip to content

Implemented setClock for the Due as well #2157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions hardware/arduino/sam/libraries/Wire/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion hardware/arduino/sam/libraries/Wire/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TwoWire : public Stream {
void begin();
void begin(uint8_t);
void begin(int);
void setClock(uint32_t);
void beginTransmission(uint8_t);
void beginTransmission(int);
uint8_t endTransmission(void);
Expand Down Expand Up @@ -99,7 +100,7 @@ class TwoWire : public Stream {
TwoWireStatus status;

// TWI clock frequency
static const uint32_t TWI_CLOCK = 100000;
uint32_t twiClock;

// Timeouts (
static const uint32_t RECV_TIMEOUT = 100000;
Expand Down
1 change: 1 addition & 0 deletions hardware/arduino/sam/libraries/Wire/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#######################################

begin KEYWORD2
setClock KEYWORD2
beginTransmission KEYWORD2
endTransmission KEYWORD2
requestFrom KEYWORD2
Expand Down