changed SusHandler MAX1227 to internal clock mode
This commit is contained in:
parent
20eb5be102
commit
50d9365702
@ -34,18 +34,14 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand(
|
|||||||
DeviceCommandId_t * id) {
|
DeviceCommandId_t * id) {
|
||||||
if (communicationStep == CommunicationStep::WRITE_SETUP) {
|
if (communicationStep == CommunicationStep::WRITE_SETUP) {
|
||||||
*id = SUS::WRITE_SETUP;
|
*id = SUS::WRITE_SETUP;
|
||||||
communicationStep = CommunicationStep::REQUEST_TEMPERATURE;
|
communicationStep = CommunicationStep::START_CONVERSIONS;
|
||||||
}
|
}
|
||||||
else if (communicationStep == CommunicationStep::REQUEST_TEMPERATURE) {
|
else if (communicationStep == CommunicationStep::START_CONVERSIONS) {
|
||||||
*id = SUS::REQUEST_TEMPERATURE;
|
*id = SUS::START_CONVERSIONS;
|
||||||
communicationStep = CommunicationStep::READ_TEMPERATURE;
|
communicationStep = CommunicationStep::READ_CONVERSIONS;
|
||||||
}
|
}
|
||||||
else if (communicationStep == CommunicationStep::READ_TEMPERATURE) {
|
else if (communicationStep == CommunicationStep::READ_CONVERSIONS) {
|
||||||
*id = SUS::READ_TEMPERATURE;
|
*id = SUS::READ_CONVERSIONS;
|
||||||
communicationStep = CommunicationStep::READ_CHANNELS;
|
|
||||||
}
|
|
||||||
else if (communicationStep == CommunicationStep::READ_CHANNELS) {
|
|
||||||
*id = SUS::READ_CHANNELS;
|
|
||||||
communicationStep = CommunicationStep::WRITE_SETUP;
|
communicationStep = CommunicationStep::WRITE_SETUP;
|
||||||
}
|
}
|
||||||
return buildCommandFromCommand(*id, nullptr, 0);
|
return buildCommandFromCommand(*id, nullptr, 0);
|
||||||
@ -69,41 +65,22 @@ ReturnValue_t SusHandler::buildCommandFromCommand(
|
|||||||
*/
|
*/
|
||||||
//TODO: Protect spi bus with mutex
|
//TODO: Protect spi bus with mutex
|
||||||
gpioComIF->pullLow(chipSelectId);
|
gpioComIF->pullLow(chipSelectId);
|
||||||
cmdBuffer[0] = SUS::SETUP_DEFINITION;
|
cmdBuffer[0] = SUS::SETUP;
|
||||||
rawPacket = cmdBuffer;
|
rawPacket = cmdBuffer;
|
||||||
rawPacketLen = 1;
|
rawPacketLen = 1;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
case(SUS::READ_CHANNELS): {
|
case(SUS::START_CONVERSIONS): {
|
||||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||||
cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0;
|
cmdBuffer[0] = SUS::CONVERSION;
|
||||||
cmdBuffer[1] = SUS::DUMMY_BYTE;
|
|
||||||
cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1;
|
|
||||||
cmdBuffer[3] = SUS::DUMMY_BYTE;
|
|
||||||
cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2;
|
|
||||||
cmdBuffer[5] = SUS::DUMMY_BYTE;
|
|
||||||
cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3;
|
|
||||||
cmdBuffer[7] = SUS::DUMMY_BYTE;
|
|
||||||
cmdBuffer[8] = SUS::CONVERT_DIFF_CHANNEL_4;
|
|
||||||
cmdBuffer[9] = SUS::DUMMY_BYTE;
|
|
||||||
cmdBuffer[10] = SUS::CONVERT_DIFF_CHANNEL_5;
|
|
||||||
cmdBuffer[11] = SUS::DUMMY_BYTE;
|
|
||||||
cmdBuffer[12] = SUS::DUMMY_BYTE;
|
|
||||||
rawPacket = cmdBuffer;
|
|
||||||
rawPacketLen = SUS::SIZE_READ_CHANNELS;
|
|
||||||
return RETURN_OK;
|
|
||||||
}
|
|
||||||
case(SUS::REQUEST_TEMPERATURE): {
|
|
||||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
|
||||||
cmdBuffer[0] = SUS::CONVERT_TEMPERATURE;
|
|
||||||
rawPacket = cmdBuffer;
|
rawPacket = cmdBuffer;
|
||||||
rawPacketLen = 1;
|
rawPacketLen = 1;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
case(SUS::READ_TEMPERATURE): {
|
case(SUS::READ_CONVERSIONS): {
|
||||||
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
|
||||||
rawPacket = cmdBuffer;
|
rawPacket = cmdBuffer;
|
||||||
rawPacketLen = 24;
|
rawPacketLen = SUS::SIZE_READ_CONVERSIONS;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -114,10 +91,8 @@ ReturnValue_t SusHandler::buildCommandFromCommand(
|
|||||||
|
|
||||||
void SusHandler::fillCommandAndReplyMap() {
|
void SusHandler::fillCommandAndReplyMap() {
|
||||||
this->insertInCommandMap(SUS::WRITE_SETUP);
|
this->insertInCommandMap(SUS::WRITE_SETUP);
|
||||||
this->insertInCommandMap(SUS::REQUEST_TEMPERATURE);
|
this->insertInCommandMap(SUS::START_CONVERSIONS);
|
||||||
this->insertInCommandAndReplyMap(SUS::READ_CHANNELS, 1, &dataset, SUS::SIZE_READ_CHANNELS);
|
this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, SUS::SIZE_READ_CONVERSIONS);
|
||||||
this->insertInCommandAndReplyMap(SUS::READ_TEMPERATURE, 1, nullptr,
|
|
||||||
SUS::SIZE_READ_TEMPERATURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SusHandler::scanForReply(const uint8_t *start,
|
ReturnValue_t SusHandler::scanForReply(const uint8_t *start,
|
||||||
@ -130,15 +105,18 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start,
|
|||||||
ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id,
|
ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id,
|
||||||
const uint8_t *packet) {
|
const uint8_t *packet) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case SUS::READ_CHANNELS: {
|
case SUS::READ_CONVERSIONS: {
|
||||||
PoolReadGuard readSet(&dataset);
|
PoolReadGuard readSet(&dataset);
|
||||||
dataset.ain0 = (*(packet + 1) << 8 | *(packet + 2));
|
dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125;
|
||||||
dataset.ain1 = (*(packet + 3) << 8 | *(packet + 4));
|
dataset.ain0 = (*(packet + 2) << 8 | *(packet + 3));
|
||||||
dataset.ain2 = (*(packet + 5) << 8 | *(packet + 6));
|
dataset.ain1 = (*(packet + 4) << 8 | *(packet + 5));
|
||||||
dataset.ain3 = (*(packet + 7) << 8 | *(packet + 8));
|
dataset.ain2 = (*(packet + 6) << 8 | *(packet + 7));
|
||||||
dataset.ain4 = (*(packet + 9) << 8 | *(packet + 10));
|
dataset.ain3 = (*(packet + 8) << 8 | *(packet + 9));
|
||||||
dataset.ain5 = (*(packet + 11) << 8 | *(packet + 12));
|
dataset.ain4 = (*(packet + 10) << 8 | *(packet + 11));
|
||||||
|
dataset.ain5 = (*(packet + 12) << 8 | *(packet + 13));
|
||||||
#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS
|
#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS
|
||||||
|
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", Temperature: "
|
||||||
|
<< dataset.temperatureCelcius << " °C" << std::endl;
|
||||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN0: "
|
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN0: "
|
||||||
<< std::dec << dataset.ain0 << std::endl;
|
<< std::dec << dataset.ain0 << std::endl;
|
||||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN1: "
|
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN1: "
|
||||||
@ -152,22 +130,10 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id,
|
|||||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN5: "
|
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN5: "
|
||||||
<< std::dec << dataset.ain5 << std::endl;
|
<< std::dec << dataset.ain5 << std::endl;
|
||||||
#endif
|
#endif
|
||||||
/**
|
/** SUS can now be shutdown and thus the SPI bus released again */
|
||||||
* Reading the channel conversion results is the last communication step in one SUS
|
|
||||||
* sequence. SPI bus can now be released again.
|
|
||||||
*/
|
|
||||||
gpioComIF->pullHigh(chipSelectId);
|
gpioComIF->pullHigh(chipSelectId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SUS::READ_TEMPERATURE: {
|
|
||||||
PoolReadGuard readSet(&dataset);
|
|
||||||
dataset.temperatureCelcius = (*(packet + 22) << 8 | *(packet + 23)) * 0.125;
|
|
||||||
#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS
|
|
||||||
sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", temperature: "
|
|
||||||
<< dataset.temperatureCelcius << " °C" << std::endl;
|
|
||||||
#endif
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
default: {
|
||||||
sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl;
|
sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl;
|
||||||
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
|
||||||
|
@ -42,9 +42,8 @@ private:
|
|||||||
|
|
||||||
enum class CommunicationStep {
|
enum class CommunicationStep {
|
||||||
WRITE_SETUP,
|
WRITE_SETUP,
|
||||||
REQUEST_TEMPERATURE,
|
START_CONVERSIONS,
|
||||||
READ_TEMPERATURE,
|
READ_CONVERSIONS
|
||||||
READ_CHANNELS
|
|
||||||
};
|
};
|
||||||
|
|
||||||
LinuxLibgpioIF* gpioComIF = nullptr;
|
LinuxLibgpioIF* gpioComIF = nullptr;
|
||||||
|
@ -18,7 +18,7 @@ namespace RAD_SENSOR {
|
|||||||
* power on.
|
* power on.
|
||||||
*
|
*
|
||||||
* @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, no data follows the setup byte
|
* @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, no data follows the setup byte
|
||||||
* Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b01, external reference single ended
|
* Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference, no wake-up delay
|
||||||
* Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing
|
* Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing
|
||||||
* Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register
|
* Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register
|
||||||
*
|
*
|
||||||
|
@ -11,55 +11,52 @@ namespace SUS {
|
|||||||
|
|
||||||
static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
|
static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
|
||||||
|
|
||||||
|
static const DeviceCommandId_t WRITE_SETUP = 0x1;
|
||||||
/**
|
/**
|
||||||
* This command initiates the ADC conversion for all channels including the internal
|
* This command initiates the ADC conversion for all channels including the internal
|
||||||
* temperature sensor.
|
* temperature sensor.
|
||||||
*/
|
*/
|
||||||
static const DeviceCommandId_t WRITE_SETUP = 0x1;
|
static const DeviceCommandId_t START_CONVERSIONS = 0x2;
|
||||||
static const DeviceCommandId_t READ_CHANNELS = 0x2;
|
/**
|
||||||
static const DeviceCommandId_t READ_TEMPERATURE = 0x3;
|
* This command reads the internal fifo which holds the temperature and the channel
|
||||||
static const DeviceCommandId_t REQUEST_TEMPERATURE = 0x4;
|
* conversions.
|
||||||
|
*/
|
||||||
|
static const DeviceCommandId_t READ_CONVERSIONS = 0x3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This is the configuration byte which will be written to the setup register after
|
* @brief This is the configuration byte which will be written to the setup register after
|
||||||
* power on.
|
* power on.
|
||||||
*
|
*
|
||||||
* @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte
|
* @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte
|
||||||
* Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference, no wake-up delay
|
* Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, Internal reference, no wake-up delay
|
||||||
* Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK
|
* Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, Internally clocked
|
||||||
* Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register
|
* Bit7 - Bit6: 0b01, Tells MAX1227 that this byte should be
|
||||||
|
* written to the setup register
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static const uint8_t SETUP_DEFINITION = 0b01111000;
|
static const uint8_t SETUP = 0b01101000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This value will always be written to the ADC conversion register to specify the
|
* @brief This values will always be written to the ADC conversion register to specify the
|
||||||
* conversions to perform.
|
* conversions to perform.
|
||||||
* @details Bit0: 1 - Enables temperature conversion
|
* @details Bit0: 1 - Enables temperature conversion
|
||||||
* Bit2 (SCAN1) and Bit1 (SCAN0): 0b11, No scan, converts channel N once only.
|
* Bit2 (SCAN1) and Bit1 (SCAN0): 0b00, Scans channels 0 through N
|
||||||
* Scanning is not supported in spi clock mode.
|
* Bit6 - Bit3 defines N: 0b0101 (N = 5)
|
||||||
* Bit6 - Bit3 defines N: 0b0001 (N = 4)
|
|
||||||
* Bit7: Always 1. Tells the ADC that this is the conversion register.
|
* Bit7: Always 1. Tells the ADC that this is the conversion register.
|
||||||
*/
|
*/
|
||||||
static const uint8_t CONVERT_TEMPERATURE = 0b10000001;
|
static const uint8_t CONVERSION = 0b10101001;
|
||||||
static const uint8_t CONVERT_DIFF_CHANNEL_0 = 0b10000110;
|
|
||||||
static const uint8_t CONVERT_DIFF_CHANNEL_1 = 0b10001110;
|
|
||||||
static const uint8_t CONVERT_DIFF_CHANNEL_2 = 0b10010110;
|
|
||||||
static const uint8_t CONVERT_DIFF_CHANNEL_3 = 0b10011110;
|
|
||||||
static const uint8_t CONVERT_DIFF_CHANNEL_4 = 0b10100110;
|
|
||||||
static const uint8_t CONVERT_DIFF_CHANNEL_5 = 0b10101110;
|
|
||||||
|
|
||||||
|
/** Writing this value resets the fifo */
|
||||||
static const uint8_t RESET_FIFO = 0b00011000;
|
static const uint8_t RESET_FIFO = 0b00011000;
|
||||||
|
|
||||||
static const uint8_t DUMMY_BYTE = 0x0;
|
static const uint8_t DUMMY_BYTE = 0x0;
|
||||||
|
|
||||||
static const uint8_t SUS_DATA_SET_ID = READ_CHANNELS;
|
static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS;
|
||||||
|
|
||||||
/** Size of data replies */
|
/** Size of data replies. Temperature and 6 channel convesions (AIN0 - AIN5) */
|
||||||
static const uint8_t SIZE_READ_CHANNELS = 13;
|
static const uint8_t SIZE_READ_CONVERSIONS = 14;
|
||||||
static const uint8_t SIZE_READ_TEMPERATURE = 25;
|
|
||||||
|
|
||||||
static const uint8_t MAX_CMD_SIZE = SIZE_READ_TEMPERATURE;
|
static const uint8_t MAX_CMD_SIZE = SIZE_READ_CONVERSIONS;
|
||||||
|
|
||||||
static const uint8_t POOL_ENTRIES = 7;
|
static const uint8_t POOL_ENTRIES = 7;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user