diff options
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino | 10 | ||||
-rw-r--r-- | libraries/SoftwareSerial/src/SoftwareSerial.cpp | 4 | ||||
-rw-r--r-- | libraries/SoftwareSerial/src/SoftwareSerial.h | 2 | ||||
-rw-r--r-- | libraries/Wire/src/Wire.cpp | 4 | ||||
-rw-r--r-- | libraries/Wire/src/utility/twi.c | 22 | ||||
-rw-r--r-- | libraries/Wire/src/utility/twi.h | 1 |
6 files changed, 30 insertions, 13 deletions
diff --git a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino index 26659d6..8d7f93e 100644 --- a/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino +++ b/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -13,8 +13,8 @@ The circuit: Two devices which communicate serially are needed. - * First serial device's TX attached to digital pin 2, RX to pin 3 - * Second serial device's TX attached to digital pin 4, RX to pin 5 + * First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX) + * Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX) Note: Not all pins on the Mega and Mega 2560 support change interrupts, @@ -26,7 +26,7 @@ 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). created 18 Apr. 2011 - modified 25 May 2012 + modified 19 March 2016 by Tom Igoe based on Mikal Hart's twoPortRXExample @@ -35,10 +35,10 @@ */ #include <SoftwareSerial.h> -// software serial #1: TX = digital pin 10, RX = digital pin 11 +// software serial #1: RX = digital pin 10, TX = digital pin 11 SoftwareSerial portOne(10, 11); -// software serial #2: TX = digital pin 8, RX = digital pin 9 +// software serial #2: RX = digital pin 8, TX = digital pin 9 // on the Mega, use other pins instead, since 8 and 9 don't work on the Mega SoftwareSerial portTwo(8, 9); diff --git a/libraries/SoftwareSerial/src/SoftwareSerial.cpp b/libraries/SoftwareSerial/src/SoftwareSerial.cpp index 0a16ff7..474fe4a 100644 --- a/libraries/SoftwareSerial/src/SoftwareSerial.cpp +++ b/libraries/SoftwareSerial/src/SoftwareSerial.cpp @@ -48,7 +48,7 @@ http://arduiniana.org. // Statics
//
SoftwareSerial *SoftwareSerial::active_object = 0;
-char SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
+uint8_t SoftwareSerial::_receive_buffer[_SS_MAX_RX_BUFF];
volatile uint8_t SoftwareSerial::_receive_buffer_tail = 0;
volatile uint8_t SoftwareSerial::_receive_buffer_head = 0;
@@ -270,7 +270,7 @@ void SoftwareSerial::setTX(uint8_t tx) {
// First write, then set output. If we do this the other way around,
// the pin would be output low for a short while before switching to
- // output hihg. Now, it is input with pullup for a short while, which
+ // output high. Now, it is input with pullup for a short while, which
// is fine. With inverse logic, either order is fine.
digitalWrite(tx, _inverse_logic ? LOW : HIGH);
pinMode(tx, OUTPUT);
diff --git a/libraries/SoftwareSerial/src/SoftwareSerial.h b/libraries/SoftwareSerial/src/SoftwareSerial.h index 622e2a5..26183ba 100644 --- a/libraries/SoftwareSerial/src/SoftwareSerial.h +++ b/libraries/SoftwareSerial/src/SoftwareSerial.h @@ -66,7 +66,7 @@ private: uint16_t _inverse_logic:1;
// static data
- static char _receive_buffer[_SS_MAX_RX_BUFF];
+ static uint8_t _receive_buffer[_SS_MAX_RX_BUFF];
static volatile uint8_t _receive_buffer_tail;
static volatile uint8_t _receive_buffer_head;
static SoftwareSerial *active_object;
diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index 86696e9..d2146f7 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -80,9 +80,9 @@ void TwoWire::end(void) twi_disable(); } -void TwoWire::setClock(uint32_t frequency) +void TwoWire::setClock(uint32_t clock) { - TWBR = ((F_CPU / frequency) - 16) / 2; + twi_setFrequency(clock); } uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop) diff --git a/libraries/Wire/src/utility/twi.c b/libraries/Wire/src/utility/twi.c index 7efcc5a..171af73 100644 --- a/libraries/Wire/src/utility/twi.c +++ b/libraries/Wire/src/utility/twi.c @@ -119,6 +119,22 @@ void twi_setAddress(uint8_t address) } /* + * Function twi_setClock + * Desc sets twi bit rate + * Input Clock Frequency + * Output none + */ +void twi_setFrequency(uint32_t frequency) +{ + TWBR = ((F_CPU / frequency) - 16) / 2; + + /* twi bit rate formula from atmega128 manual pg 204 + SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR)) + note: TWBR should be 10 or higher for master mode + It is 72 for a 16mhz Wiring board with 100kHz TWI */ +} + +/* * Function twi_readFrom * Desc attempts to become twi bus master and read a * series of bytes from a device on the bus @@ -288,7 +304,7 @@ uint8_t twi_transmit(const uint8_t* data, uint8_t length) uint8_t i; // ensure data will fit into buffer - if(TWI_BUFFER_LENGTH < length){ + if(TWI_BUFFER_LENGTH < (twi_txBufferLength+length)){ return 1; } @@ -298,10 +314,10 @@ uint8_t twi_transmit(const uint8_t* data, uint8_t length) } // set length and copy data into tx buffer - twi_txBufferLength = length; for(i = 0; i < length; ++i){ - twi_txBuffer[i] = data[i]; + twi_txBuffer[twi_txBufferLength+i] = data[i]; } + twi_txBufferLength += length; return 0; } diff --git a/libraries/Wire/src/utility/twi.h b/libraries/Wire/src/utility/twi.h index 4c52bc5..d27325e 100644 --- a/libraries/Wire/src/utility/twi.h +++ b/libraries/Wire/src/utility/twi.h @@ -41,6 +41,7 @@ void twi_init(void); void twi_disable(void); void twi_setAddress(uint8_t); + void twi_setFrequency(uint32_t); uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t); uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t); uint8_t twi_transmit(const uint8_t*, uint8_t); |