simple rm3100 test working now
This commit is contained in:
@ -1,16 +1,18 @@
|
||||
#include "SpiTestClass.h"
|
||||
|
||||
#include <fsfwconfig/devices/gpioIds.h>
|
||||
|
||||
#include <fsfw/serviceinterface/ServiceInterface.h>
|
||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <fcntl.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <fsfw/timemanager/Stopwatch.h>
|
||||
|
||||
#include <linux/gpio/gpioDefinitions.h>
|
||||
#include <linux/gpio/GpioCookie.h>
|
||||
#include <linux/utility/Utility.h>
|
||||
|
||||
#include <linux/spi/spidev.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <bitset>
|
||||
@ -69,7 +71,7 @@ void SpiTestClass::performRm3100Test(uint8_t mgmId) {
|
||||
else {
|
||||
currentGpioId = gpioIds::MGM_3_RM3100_CS;
|
||||
}
|
||||
uint32_t rm3100speed = 195'300;
|
||||
uint32_t rm3100speed = 976'000;
|
||||
uint8_t rm3100revidReg = 0x36;
|
||||
spi::SpiMode rm3100mode = spi::SpiMode::MODE_3;
|
||||
|
||||
@ -96,7 +98,6 @@ void SpiTestClass::performRm3100Test(uint8_t mgmId) {
|
||||
|
||||
/* Write configuration to CMM register */
|
||||
writeRegister(fileDescriptor, currentGpioId, 0x01, 0x75);
|
||||
// TaskFactory::delayTask(10);
|
||||
uint8_t cmmRegister = readRm3100Register(fileDescriptor , currentGpioId, 0x01);
|
||||
sif::info << "SpiTestClass::performRm3100Test: CMM register value: " <<
|
||||
std::hex << "0x" << static_cast<int>(cmmRegister) << std::dec << std::endl;
|
||||
@ -104,7 +105,54 @@ void SpiTestClass::performRm3100Test(uint8_t mgmId) {
|
||||
/* Read the cycle count registers */
|
||||
uint8_t cycleCountsRaw[6];
|
||||
readMultipleRegisters(fileDescriptor, currentGpioId, 0x04, cycleCountsRaw, 6);
|
||||
arrayprinter::print(cycleCountsRaw, 6);
|
||||
|
||||
uint16_t cycleCountX = cycleCountsRaw[0] << 8 | cycleCountsRaw[1];
|
||||
uint16_t cycleCountY = cycleCountsRaw[2] << 8 | cycleCountsRaw[3];
|
||||
uint16_t cycleCountZ = cycleCountsRaw[4] << 8 | cycleCountsRaw[5];
|
||||
|
||||
sif::info << "Cycle count X: " << cycleCountX << std::endl;
|
||||
sif::info << "Cycle count Y: " << cycleCountY << std::endl;
|
||||
sif::info << "Cycle count z: " << cycleCountZ << std::endl;
|
||||
|
||||
writeRegister(fileDescriptor, currentGpioId, 0x0B, 0x95);
|
||||
uint8_t tmrcReg = readRm3100Register(fileDescriptor, currentGpioId, 0x0B);
|
||||
sif::info << "SpiTestClass::performRm3100Test: TMRC register value: " <<
|
||||
std::hex << "0x" << static_cast<int>(tmrcReg) << std::dec << std::endl;
|
||||
|
||||
TaskFactory::delayTask(10);
|
||||
uint8_t statusReg = readRm3100Register(fileDescriptor, currentGpioId, 0x34);
|
||||
sif::info << "SpiTestClass::performRm3100Test: Status Register 0b" <<
|
||||
std::bitset<8>(statusReg) << std::endl;
|
||||
/* This means that data is not ready */
|
||||
if((statusReg & 0b1000'0000) == 0) {
|
||||
sif::warning << "SpiTestClass::performRm3100Test: Data not ready!" << std::endl;
|
||||
TaskFactory::delayTask(10);
|
||||
uint8_t statusReg = readRm3100Register(fileDescriptor, currentGpioId, 0x34);
|
||||
if((statusReg & 0b1000'0000) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t rm3100DefaultCycleCout = 0xC8;
|
||||
/* Gain scales lineary with cycle count and is 38 for cycle count 100 */
|
||||
float rm3100Gain = rm3100DefaultCycleCout / 100.0 * 38.0;
|
||||
float scaleFactor = 1 / rm3100Gain;
|
||||
uint8_t rawValues[9];
|
||||
readMultipleRegisters(fileDescriptor, currentGpioId, 0x24, rawValues, 9);
|
||||
|
||||
/* The sensor generates 24 bit signed values */
|
||||
int32_t rawX = ((rawValues[0] << 24) | (rawValues[1] << 16) | (rawValues[2] << 8)) >> 8;
|
||||
int32_t rawY = ((rawValues[3] << 24) | (rawValues[4] << 16) | (rawValues[5] << 8)) >> 8;
|
||||
int32_t rawZ = ((rawValues[6] << 24) | (rawValues[7] << 16) | (rawValues[8] << 8)) >> 8;
|
||||
|
||||
float fieldStrengthX = rawX * scaleFactor;
|
||||
float fieldStrengthY = rawY * scaleFactor;
|
||||
float fieldStrengthZ = rawZ * scaleFactor;
|
||||
|
||||
sif::info << "RM3100 measured field strenghts in microtesla:" << std::endl;
|
||||
sif::info << "Field Strength X: " << fieldStrengthX << " \xC2\xB5T" << std::endl;
|
||||
sif::info << "Field Strength Y: " << fieldStrengthY << " \xC2\xB5T" << std::endl;
|
||||
sif::info << "Field Strength Z: " << fieldStrengthZ << " \xC2\xB5T" << std::endl;
|
||||
}
|
||||
|
||||
void SpiTestClass::performLis3MdlTest(uint8_t lis3Id) {
|
||||
@ -242,10 +290,14 @@ void SpiTestClass::readMultipleRegisters(int fd, gpioId_t chipSelect, uint8_t re
|
||||
|
||||
spiTransferStruct.len = len + 1;
|
||||
sendBuffer[0] = reg | STM_READ_MASK;
|
||||
|
||||
for(uint8_t idx = 0; idx < len ; idx ++) {
|
||||
sendBuffer[idx + 1] = 0;
|
||||
}
|
||||
|
||||
if(gpioIF != nullptr and chipSelect != gpio::NO_GPIO) {
|
||||
gpioIF->pullLow(chipSelect);
|
||||
}
|
||||
int retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if(retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::readRegister: Read failed");
|
||||
|
@ -28,7 +28,7 @@ private:
|
||||
|
||||
std::array<uint8_t, 128> recvBuffer;
|
||||
std::array<uint8_t, 128> sendBuffer;
|
||||
struct spi_ioc_transfer spiTransferStruct;
|
||||
struct spi_ioc_transfer spiTransferStruct = {};
|
||||
|
||||
void performRm3100Test(uint8_t mgmId);
|
||||
void performLis3MdlTest(uint8_t lis3Id);
|
||||
|
Reference in New Issue
Block a user