mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
max31723: made it work with SPI but the data looks like incorrect
Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
This commit is contained in:
parent
1747fbbe19
commit
d0e83d7076
@ -45,11 +45,12 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
sensor = new upm::MAX31723(7);
|
sensor = new upm::MAX31723(7);
|
||||||
|
usleep (1000000);
|
||||||
|
|
||||||
// while (!doWork) {
|
while (!doWork) {
|
||||||
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
|
std::cout << "Temperature " << sensor->getTemperature() << std::endl;
|
||||||
// usleep (3000000);
|
usleep (1000000);
|
||||||
// }
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
|
||||||
std::cout << "exiting application" << std::endl;
|
std::cout << "exiting application" << std::endl;
|
||||||
|
@ -51,12 +51,17 @@ MAX31723::MAX31723 (int csn) {
|
|||||||
throw MAX31723Exception ("GPIO failed to initilize");
|
throw MAX31723Exception ("GPIO failed to initilize");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSOff ();
|
||||||
|
|
||||||
m_spi = mraa_spi_init (0);
|
m_spi = mraa_spi_init (0);
|
||||||
if (m_spi == NULL) {
|
if (m_spi == NULL) {
|
||||||
throw MAX31723Exception ("SPI failed to initilize");
|
throw MAX31723Exception ("SPI failed to initilize");
|
||||||
}
|
}
|
||||||
|
|
||||||
CSOff ();
|
// set spi mode to mode2 (CPOL = 1, CPHA = 0)
|
||||||
|
mraa_spi_mode (m_spi, MODE2);
|
||||||
|
// set ontinuously perform temperature conversions
|
||||||
|
writeRegister (R_STS_WRITE_CMD, B_CONT_READING);
|
||||||
}
|
}
|
||||||
|
|
||||||
MAX31723::~MAX31723() {
|
MAX31723::~MAX31723() {
|
||||||
@ -72,31 +77,24 @@ MAX31723::~MAX31723() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t
|
short
|
||||||
MAX31723::getTemperature () {
|
MAX31723::getTemperature () {
|
||||||
uint8_t lsb = 0;
|
uint8_t lsb = 0;
|
||||||
uint8_t msb = 0;
|
uint8_t msb = 0;
|
||||||
uint8_t buf[2] = { 0x01, 0x00};
|
short temperature = 0;
|
||||||
|
|
||||||
CSOn ();
|
lsb = readRegister (R_TEMPERATURE_LSB);
|
||||||
|
msb = readRegister (R_TEMPERATURE_MSB);
|
||||||
|
|
||||||
uint8_t* x = mraa_spi_write_buf(m_spi, buf, 2);
|
if ((msb & 0x80) != 0) {
|
||||||
|
msb &= 0x7F;
|
||||||
|
temperature = 0 - msb;
|
||||||
|
|
||||||
printf ("%d\n", (uint16_t)*x);
|
} else {
|
||||||
|
temperature = msb;
|
||||||
|
}
|
||||||
|
|
||||||
/*mraa_spi_write (m_spi, R_TEMPERATURE_LSB);
|
return temperature;
|
||||||
lsb = mraa_spi_write (m_spi, lsb);
|
|
||||||
lsb >>= 4;*/
|
|
||||||
|
|
||||||
/*mraa_spi_write (m_spi, R_TEMPERATURE_MSB);
|
|
||||||
msb = mraa_spi_write (m_spi, msb);
|
|
||||||
|
|
||||||
if ((msb & 0x80) != 0)
|
|
||||||
msb |= ~((1 << 8) - 1);*/
|
|
||||||
|
|
||||||
CSOff ();
|
|
||||||
|
|
||||||
return msb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -105,6 +103,31 @@ MAX31723::getTemperature () {
|
|||||||
* **************
|
* **************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
uint8_t
|
||||||
|
MAX31723::readRegister (uint8_t reg) {
|
||||||
|
uint8_t data[2] = { 0x00, 0x00 };
|
||||||
|
uint8_t* sensorData = NULL;
|
||||||
|
|
||||||
|
CSOn ();
|
||||||
|
data[0] = reg;
|
||||||
|
sensorData = mraa_spi_write_buf(m_spi, data, 2);
|
||||||
|
CSOff ();
|
||||||
|
|
||||||
|
return sensorData[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MAX31723::writeRegister (uint8_t reg, uint8_t data) {
|
||||||
|
uint8_t buffer[2] = { 0x00, 0x00 };
|
||||||
|
uint8_t* sensorData = NULL;
|
||||||
|
|
||||||
|
CSOn ();
|
||||||
|
buffer[0] = reg;
|
||||||
|
buffer[1] = data;
|
||||||
|
sensorData = mraa_spi_write_buf(m_spi, buffer, 2);
|
||||||
|
CSOff ();
|
||||||
|
}
|
||||||
|
|
||||||
mraa_result_t
|
mraa_result_t
|
||||||
MAX31723::CSOn () {
|
MAX31723::CSOn () {
|
||||||
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
return mraa_gpio_write (m_csnPinCtx, HIGH);
|
||||||
|
@ -46,6 +46,8 @@ class MAX31723 {
|
|||||||
static const uint8_t R_TEMPERATURE_LSB = 0x01;
|
static const uint8_t R_TEMPERATURE_LSB = 0x01;
|
||||||
static const uint8_t R_TEMPERATURE_MSB = 0x02;
|
static const uint8_t R_TEMPERATURE_MSB = 0x02;
|
||||||
|
|
||||||
|
static const uint8_t B_CONT_READING = 0x00;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instanciates a MAX31723 object
|
* Instanciates a MAX31723 object
|
||||||
*
|
*
|
||||||
@ -62,7 +64,7 @@ class MAX31723 {
|
|||||||
/**
|
/**
|
||||||
* Get on board temperature.
|
* Get on board temperature.
|
||||||
*/
|
*/
|
||||||
uint16_t getTemperature ();
|
short getTemperature ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return name of the component
|
* Return name of the component
|
||||||
@ -76,6 +78,9 @@ class MAX31723 {
|
|||||||
mraa_spi_context m_spi;
|
mraa_spi_context m_spi;
|
||||||
mraa_gpio_context m_csnPinCtx;
|
mraa_gpio_context m_csnPinCtx;
|
||||||
|
|
||||||
|
uint8_t readRegister (uint8_t reg);
|
||||||
|
void writeRegister (uint8_t reg, uint8_t data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set chip select pin LOW
|
* Set chip select pin LOW
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user