summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanley Huang <stanleyhuangyc@gmail.com>2015-05-04 10:51:15 +1000
committerStanley Huang <stanleyhuangyc@gmail.com>2015-05-04 10:51:15 +1000
commitc56afd24349d1b4bdf1befe0622a30a2c15c9b48 (patch)
tree5d8932de4e5bdecc86a3457395a10c34d3ccb678
parent7b7ece282d05232c705f1b0b0b51da0ad2b9733e (diff)
download2021-arduino-obd-c56afd24349d1b4bdf1befe0622a30a2c15c9b48.tar.gz
2021-arduino-obd-c56afd24349d1b4bdf1befe0622a30a2c15c9b48.tar.bz2
2021-arduino-obd-c56afd24349d1b4bdf1befe0622a30a2c15c9b48.zip
Fix setBaudRate(), add necessary delay in receive()
-rw-r--r--libraries/OBD/OBD.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp
index bf778bf..72955f0 100644
--- a/libraries/OBD/OBD.cpp
+++ b/libraries/OBD/OBD.cpp
@@ -378,8 +378,9 @@ void COBD::end()
bool COBD::setBaudRate(unsigned long baudrate)
{
char buf[OBD_RECV_BUF_SIZE];
- sprintf(buf, "ATBR2 %lu\r", baudrate);
- OBDUART.print(buf);
+ OBDUART.print("ATBR1 ");
+ OBDUART.print(baudrate);
+ OBDUART.print('\r');
if (receive(buf) && strstr(buf, "OK")) {
OBDUART.end();
OBDUART.begin(baudrate);
@@ -503,6 +504,7 @@ byte COBDI2C::receive(char* buffer, int timeout)
{
uint32_t start = millis();
byte offset = 0;
+ delay(10);
do {
Wire.requestFrom((byte)I2C_ADDR, (byte)MAX_PAYLOAD_SIZE, (byte)1);