v1.10.0 #220
@ -29,8 +29,8 @@ static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3;
|
||||
*/
|
||||
static const uint32_t SUS_MAX1227_SPI_FREQ = 976'000;
|
||||
|
||||
static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 976'000;
|
||||
static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3;
|
||||
static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 4'000'000;
|
||||
static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0;
|
||||
|
||||
static constexpr uint32_t DEFAULT_ADIS16507_SPEED = 976'000;
|
||||
static constexpr spi::SpiModes DEFAULT_ADIS16507_MODE = spi::SpiModes::MODE_3;
|
||||
|
@ -281,9 +281,10 @@ void SpiTestClass::performL3gTest(uint8_t l3gId) {
|
||||
|
||||
void SpiTestClass::performMax1227Test() {
|
||||
using namespace max1227;
|
||||
bool testRadSensor = false;
|
||||
bool extConversion = true;
|
||||
bool intConversion = false;
|
||||
bool testRadSensorExtConv = false;
|
||||
bool testRadSensorIntConv = false;
|
||||
bool extConversion = false;
|
||||
bool intConversion = true;
|
||||
#ifdef XIPHOS_Q7S
|
||||
std::string deviceName = q7s::SPI_DEFAULT_DEV;
|
||||
#elif defined(RASPBERRY_PI)
|
||||
@ -301,7 +302,7 @@ void SpiTestClass::performMax1227Test() {
|
||||
spi::SpiModes spiMode = spi::SpiModes::MODE_3;
|
||||
setSpiSpeedAndMode(fd, spiMode, spiSpeed);
|
||||
|
||||
if (testRadSensor) {
|
||||
if (testRadSensorExtConv) {
|
||||
sendBuffer[0] = max1227::buildResetByte(true);
|
||||
sendBuffer[1] = max1227::buildSetupByte(ClkSel::EXT_CONV_EXT_TIMED, RefSel::INT_REF_NO_WAKEUP,
|
||||
DiffSel::NONE_0);
|
||||
@ -314,11 +315,64 @@ void SpiTestClass::performMax1227Test() {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
max1227::prepareExternallyClockedSingleChannelRead(sendBuffer.data(), 0,
|
||||
spiTransferStruct[0].len);
|
||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 7, spiTransferStruct[0].len);
|
||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
arrayprinter::print(recvBuffer.data(), 13, OutputType::HEX);
|
||||
uint16_t adcRaw[8] = {};
|
||||
adcRaw[0] = (recvBuffer[1] << 8) | recvBuffer[2];
|
||||
adcRaw[1] = (recvBuffer[3] << 8) | recvBuffer[4];
|
||||
adcRaw[2] = (recvBuffer[5] << 8) | recvBuffer[6];
|
||||
adcRaw[3] = (recvBuffer[7] << 8) | recvBuffer[8];
|
||||
adcRaw[4] = (recvBuffer[9] << 8) | recvBuffer[10];
|
||||
adcRaw[5] = (recvBuffer[11] << 8) | recvBuffer[12];
|
||||
adcRaw[6] = (recvBuffer[13] << 8) | recvBuffer[14];
|
||||
adcRaw[7] = (recvBuffer[15] << 8) | recvBuffer[16];
|
||||
arrayprinter::print(recvBuffer.data(), 17, OutputType::HEX);
|
||||
for (int idx = 0; idx < 8; idx++) {
|
||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
if (testRadSensorIntConv) {
|
||||
sendBuffer[0] = max1227::buildResetByte(false);
|
||||
spiTransferStruct[0].len = 1;
|
||||
ReturnValue_t result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
usleep(65);
|
||||
|
||||
// Now use internal conversion
|
||||
sendBuffer[0] = max1227::buildSetupByte(ClkSel::INT_CONV_INT_TIMED_CNVST_AS_AIN,
|
||||
RefSel::INT_REF_NO_WAKEUP, DiffSel::NONE_0);
|
||||
spiTransferStruct[0].len = 1;
|
||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
usleep(10);
|
||||
sendBuffer[0] = buildConvByte(ScanModes::CHANNELS_0_TO_N, 7, true);
|
||||
spiTransferStruct[0].len = 1;
|
||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
@ -326,12 +380,14 @@ void SpiTestClass::performMax1227Test() {
|
||||
if (retval < 0) {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
arrayprinter::print(recvBuffer.data(), 3);
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
|
||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len);
|
||||
usleep(65);
|
||||
spiTransferStruct[0].len = 18;
|
||||
// Shift out zeros
|
||||
spiTransferStruct[0].tx_buf = 0;
|
||||
result = gpioIF->pullLow(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
@ -342,7 +398,23 @@ void SpiTestClass::performMax1227Test() {
|
||||
result = gpioIF->pullHigh(gpioIds::CS_RAD_SENSOR);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
}
|
||||
arrayprinter::print(recvBuffer.data(), 13., OutputType::DEC);
|
||||
|
||||
arrayprinter::print(recvBuffer.data(), 14);
|
||||
uint16_t adcRaw[8] = {};
|
||||
int16_t tempRaw = ((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1];
|
||||
|
||||
sif::info << "Temperature: " << tempRaw * 0.125 << " C" << std::endl;
|
||||
adcRaw[0] = (recvBuffer[2] << 8) | recvBuffer[3];
|
||||
adcRaw[1] = (recvBuffer[4] << 8) | recvBuffer[5];
|
||||
adcRaw[2] = (recvBuffer[6] << 8) | recvBuffer[7];
|
||||
adcRaw[3] = (recvBuffer[8] << 8) | recvBuffer[9];
|
||||
adcRaw[4] = (recvBuffer[10] << 8) | recvBuffer[11];
|
||||
adcRaw[5] = (recvBuffer[12] << 8) | recvBuffer[13];
|
||||
adcRaw[6] = (recvBuffer[14] << 8) | recvBuffer[15];
|
||||
adcRaw[7] = (recvBuffer[16] << 8) | recvBuffer[17];
|
||||
for (int idx = 0; idx < 8; idx++) {
|
||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
if (extConversion) {
|
||||
sendBuffer[0] = max1227::buildResetByte(false);
|
||||
@ -361,15 +433,6 @@ void SpiTestClass::performMax1227Test() {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
|
||||
// usleep(4);
|
||||
// max1227::prepareExternallyClockedSingleChannelRead(sendBuffer.data(), 0,
|
||||
// spiTransferStruct[0].len);
|
||||
// retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
// if (retval < 0) {
|
||||
// utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
// }
|
||||
// arrayprinter::print(recvBuffer.data(), 3);
|
||||
|
||||
max1227::prepareExternallyClockedRead0ToN(sendBuffer.data(), 5, spiTransferStruct[0].len);
|
||||
retval = ioctl(fd, SPI_IOC_MESSAGE(1), &spiTransferStruct);
|
||||
if (retval < 0) {
|
||||
@ -421,6 +484,18 @@ void SpiTestClass::performMax1227Test() {
|
||||
utility::handleIoctlError("SpiTestClass::writeRegister: Write failed");
|
||||
}
|
||||
arrayprinter::print(recvBuffer.data(), 14);
|
||||
float temp = static_cast<int16_t>(((recvBuffer[0] & 0x0f) << 8) | recvBuffer[1]) * 0.125;
|
||||
sif::info << "Temperature: " << temp << " C" << std::endl;
|
||||
uint16_t adcRaw[6] = {};
|
||||
adcRaw[0] = (recvBuffer[2] << 8) | recvBuffer[3];
|
||||
adcRaw[1] = (recvBuffer[4] << 8) | recvBuffer[5];
|
||||
adcRaw[2] = (recvBuffer[6] << 8) | recvBuffer[7];
|
||||
adcRaw[3] = (recvBuffer[8] << 8) | recvBuffer[9];
|
||||
adcRaw[4] = (recvBuffer[10] << 8) | recvBuffer[11];
|
||||
adcRaw[5] = (recvBuffer[12] << 8) | recvBuffer[13];
|
||||
for (int idx = 0; idx < 6; idx++) {
|
||||
sif::info << "ADC raw " << idx << ": " << adcRaw[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user