From 6861cd399ef4bc48aeac6927cac05ed0f28e3fa9 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sat, 8 May 2021 22:49:21 +0200 Subject: [PATCH] some tries to get data from max1227 in externally clocked mode --- bsp_q7s/ObjectFactory.cpp | 2 +- fsfwconfig/OBSWConfig.h | 2 +- fsfwconfig/devices/spi.h | 2 +- mission/devices/SusHandler.cpp | 41 ++++++++++--------- mission/devices/SusHandler.h | 1 + .../devicedefinitions/SusDefinitions.h | 9 ++-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 6af5921b..5dae58db 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -228,7 +228,7 @@ void ObjectFactory::produce(){ SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, + SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 5db2e7d0..ea73eb1c 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,7 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 0 +#define TE0720 1 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 9558fb89..18b91c6f 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -21,7 +21,7 @@ static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; //static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1'000'000; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1000000; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; } diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 2ebe1858..0469f60c 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -33,9 +33,13 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { *id = SUS::PERFORM_CONVERSIONS; - communicationStep = CommunicationStep::READ_TEMP; + communicationStep = CommunicationStep::REQUEST_TEMP; // communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } + else if (communicationStep == CommunicationStep::REQUEST_TEMP) { + *id = SUS::RQUEST_TEMP; + communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + } else if (communicationStep == CommunicationStep::READ_TEMP) { *id = SUS::READ_TEMP; communicationStep = CommunicationStep::PERFORM_CONVERSIONS; @@ -66,7 +70,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( return RETURN_OK; } case(SUS::PERFORM_CONVERSIONS): { - gpioComIF->pullLow(chipSelectId); +// gpioComIF->pullLow(chipSelectId); std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); /** * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a @@ -76,18 +80,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_0_1; -// struct timeval startOfDelay; -// gettimeofday(&startOfDelay, NULL); -// struct timeval currentTime; -// gettimeofday(¤tTime, NULL); -// while (currentTime.tv_usec - startOfDelay.tv_usec < 1000) { -// gettimeofday(¤tTime, NULL); -// } - -// cmdBuffer[27] = SUS::CONVERT_DIFF_CHANNEL_0_1; -// cmdBuffer[29] = SUS::CONVERT_DIFF_CHANNEL_2_3; -// cmdBuffer[31] = SUS::CONVERT_DIFF_CHANNEL_4_5; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_2; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; @@ -100,13 +93,20 @@ ReturnValue_t SusHandler::buildCommandFromCommand( rawPacketLen = 5; return RETURN_OK; } + case(SUS::RQUEST_TEMP): { +// gpioComIF->pullLow(chipSelectId); + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); +// cmdBuffer[0] = SUS::RESET_FIFO; +// cmdBuffer[1] = SUS::SETUP_DEFINITION; + cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; + rawPacket = cmdBuffer; + rawPacketLen = 25; + return RETURN_OK; + } case(SUS::READ_TEMP): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - cmdBuffer[0] = SUS::RESET_FIFO; - cmdBuffer[1] = SUS::SETUP_DEFINITION; - cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; - rawPacketLen = 27; + rawPacketLen = 0; return RETURN_OK; } default: @@ -122,7 +122,7 @@ void SusHandler::fillCommandAndReplyMap() { this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, nullptr, SUS::SIZE_PERFORM_CONVERSIONS); // this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, // SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandMap(SUS::PERFORM_CONVERSIONS); + this->insertInCommandMap(SUS::RQUEST_TEMP); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -136,6 +136,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { case SUS::PERFORM_CONVERSIONS: { +// gpioComIF->pullHigh(chipSelectId); PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); @@ -154,7 +155,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, break; } case SUS::READ_TEMP: { - gpioComIF->pullHigh(chipSelectId); +// gpioComIF->pullHigh(chipSelectId); break; } default: { diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index e5cc68ae..2fb2a6a8 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -42,6 +42,7 @@ private: enum class CommunicationStep { PERFORM_CONVERSIONS, + REQUEST_TEMP, READ_TEMP }; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 1b3cbe70..6e795775 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -12,6 +12,7 @@ namespace SUS { static const DeviceCommandId_t WRITE_SETUP = 0x1; static const DeviceCommandId_t PERFORM_CONVERSIONS = 0x2; static const DeviceCommandId_t READ_TEMP = 0x3; + static const DeviceCommandId_t RQUEST_TEMP = 0x4; /** * @brief This is the configuration byte which will be written to the setup register after @@ -35,9 +36,11 @@ namespace SUS { * Bit7: Always 1. Tells the ADC that this is the conversion register. */ static const uint8_t CONVERT_TEMPERATURE = 0b10000001; - static const uint8_t CONVERT_DIFF_CHANNEL_0_1 = 0b10000110; - static const uint8_t CONVERT_DIFF_CHANNEL_2_3 = 0b10010110; - static const uint8_t CONVERT_DIFF_CHANNEL_4_5 = 0b10100110; + 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 RESET_FIFO = 0b00011000;