Skip to content

Commit

Permalink
Merge pull request MarlinFirmware#33 from CELLINKAB/tmp117-error-value
Browse files Browse the repository at this point in the history
Tmp117 error value
  • Loading branch information
Skyelar Craver authored Oct 25, 2022
2 parents f16506e + 965279d commit c2fed91
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
34 changes: 19 additions & 15 deletions Marlin/src/feature/tmp117/TMP117.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
*/

#include "TMP117.h"

#include <Wire.h>
#include <cstring>

/**
* @brief Construct a new template<typename Bus>
Expand All @@ -27,7 +29,7 @@ TMP117<Bus>::TMP117(TMPAddr addr, Bus& alt_bus)
, alert_type(TMP117_ALERT::NOALERT)
, newDataCallback(nullptr)
{
bus.begin();
bus.begin();
}

/**
Expand All @@ -45,15 +47,15 @@ TMP117<Bus>::TMP117(uint8_t addr, Bus& alt_bus)
, alert_type(TMP117_ALERT::NOALERT)
, newDataCallback(nullptr)
{
bus.begin();
bus.begin();
}

/*!
@brief Initialize in default mode
@param _newDataCallback callback function will be called when new data is available
*/
template<typename Bus> void
TMP117<Bus>::init(void (*_newDataCallback)(void))
template<typename Bus>
void TMP117<Bus>::init(void (*_newDataCallback)(void))
{
setConvMode(TMP117_CMODE::CONTINUOUS);
setConvTime(TMP117_CONVT::C125mS);
Expand All @@ -68,7 +70,7 @@ TMP117<Bus>::init(void (*_newDataCallback)(void))
@brief Read configuration register and handle events.
Should be called in loop in order to call callback functions
*/
template<typename Bus>
template<typename Bus>
void TMP117<Bus>::update(void)
{
readConfig();
Expand Down Expand Up @@ -368,7 +370,6 @@ uint16_t TMP117<Bus>::readEEPROM(uint8_t eeprom_nr)
/* ********************* Library internal functions ******************** */
/**************************************************************************/


/*!
@brief Write two bytes (16 bits) to TMP117 I2C sensor
Expand All @@ -380,8 +381,8 @@ void TMP117<Bus>::i2cWrite2B(uint8_t reg, uint16_t data)
{
bus.beginTransmission(address);
bus.write(reg);
bus.write((data >> 8));
bus.write((data & 0xff));
bus.write(static_cast<uint8_t>(data >> 8));
bus.write(static_cast<uint8_t>(data & 0xff));
bus.endTransmission();
delay(10);
}
Expand All @@ -396,18 +397,21 @@ void TMP117<Bus>::i2cWrite2B(uint8_t reg, uint16_t data)
template<typename Bus>
uint16_t TMP117<Bus>::i2cRead2B(uint8_t reg)
{
uint8_t data[2] = {0};
int16_t datac = 0;
uint8_t data[2]{};
int16_t datac; // error value

bus.beginTransmission(address);
bus.write(reg);
bus.endTransmission();
bus.requestFrom((uint8_t) address, (uint8_t) 2);
if (bus.available() <= 2) {
data[0] = bus.read();
data[1] = bus.read();
datac = ((data[0] << 8) | data[1]);
}

// bus byte order is opposite of memcpy byte order
// bus.available() always returns true so don't bother checking
data[1] = bus.read();
data[0] = bus.read();
std::memcpy(&datac, data, 2);

bus.flush();
return datac;
}

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/pins/stm32f7/pins_NUCLEO_F746ZG.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@
// Temperature Sensors
//

#define I2C_SCL_PIN PF13
#define I2C_SDA_PIN PE9
#define I2C_SCL_PIN PB8
#define I2C_SDA_PIN PB9

#define TEMP_0_PIN PA3
#define TEMP_1_PIN PC3
Expand Down

0 comments on commit c2fed91

Please sign in to comment.