AnsweredAssumed Answered

adi_AFE_RunSequence causes Bus-Fault

Question asked by enpa on Sep 21, 2017

Dear all

 

I've implemented the following functions:

 

void afeInit()
{
    adi_AFE_Init(&hAfe);
}

int32_t afeRunCompleteSequence()
{
    int32_t offset;
    uint32_t gain;
    int32_t degC;

   adi_AFE_RunSequence(hAfe, seqMT_afe_afePowerup, (uint16_t*)rxBuffer, 0);

   adi_AFE_RunSequence(hAfe, seqMT_afe_tempSensChanCal, (uint16_t*)rxBuffer, 3);

   gain = (19115 * 16384 * 2) / (rxBuffer[2] - rxBuffer[1]);
    gain = (gain & 0x00000001)?(gain >> 1) + 1:gain >> 1;
    offset = (32768 - rxBuffer[0]) << 2;
    adi_AFE_WriteCalibrationRegister(hAfe, ADI_AFE_CAL_REG_ADC_OFFSET_TEMP_SENS, offset);
    adi_AFE_WriteCalibrationRegister(hAfe, ADI_AFE_CAL_REG_ADC_GAIN_TEMP_SENS, gain);
  
   adi_AFE_RunSequence(hAfe, seqMT_afe_tempSensMeas, (uint16_t*)rxBuffer, 0);
   degC = ((int32_t)pADI_AFE->AFE_TEMP_SENSOR_RESULT - 3414) * 2 * 2 / 25;
    degC = (degC & 0x00000001)?(degC >> 1) + 1:degC >> 1;

   adi_AFE_PowerDown(hAfe);
   return degC;
}

 

If I call afeInit() folowed by afeRunCompleteSequence(), everything works perfectly.

The only issue is that the complete sequence will be longer and the processor needs to perform other time sensitive tasks (e.g. communication) at the same time. This is why I tried to run the sequencen in non-blocking mode.

 

This is the code I came up with (actually is almost the same as emoloney's example from this thread: adi_AFE_RunSequence() in non-blocking):

 

void afeInit()
{
    adi_AFE_Init(&hAfe);

   adi_AFE_SetRunSequenceBlockingMode(hAfe, false);
    adi_AFE_EnableSoftwareCRC(hAfe, true);

   adi_AFE_RegisterAfeCallback(hAfe, ADI_AFE_INT_GROUP_CMD_FIFO, CmdFifoInterruptCallback, BITM_AFE_AFE_CMD_FIFO_INT_END_OF_SEQ);
    adi_AFE_RegisterCallbackOnReceiveDMA(hAfe, RxDmaInterruptCallback, 0);
}

int32_t afeRunCompleteSequence()
{
    int32_t offset;
    uint32_t gain;
    int32_t degC;
  
   sequenceFinished = false;
    adi_AFE_RunSequence(hAfe, seqMT_afe_afePowerup, (uint16_t*)rxBuffer, 0);
    while(sequenceFinished != false);
    adi_AFE_SetSeqState(hAfe, ADI_AFE_SEQ_STATE_FINISHED);
    adi_AFE_SeqStop(hAfe);
    adi_AFE_SetSeqState(hAfe, ADI_AFE_SEQ_STATE_IDLE);

   sequenceFinished = false;
    adi_AFE_RunSequence(hAfe, seqMT_afe_tempSensChanCal, (uint16_t*)rxBuffer, 3);
    while(sequenceFinished != false);
    adi_AFE_SetSeqState(hAfe, ADI_AFE_SEQ_STATE_FINISHED);
    adi_AFE_SeqStop(hAfe);
    adi_AFE_SetSeqState(hAfe, ADI_AFE_SEQ_STATE_IDLE);

   gain = (19115 * 16384 * 2) / (rxBuffer[2] - rxBuffer[1]);
    gain = (gain & 0x00000001)?(gain >> 1) + 1:gain >> 1;
    offset = (32768 - rxBuffer[0]) << 2;
    adi_AFE_WriteCalibrationRegister(hAfe, ADI_AFE_CAL_REG_ADC_OFFSET_TEMP_SENS, offset);
    adi_AFE_WriteCalibrationRegister(hAfe, ADI_AFE_CAL_REG_ADC_GAIN_TEMP_SENS, gain);

   sequenceFinished = false;
    adi_AFE_RunSequence(hAfe, seqMT_afe_tempSensMeas, (uint16_t*)rxBuffer, 0);
    while(sequenceFinished != false);
    adi_AFE_SetSeqState(hAfe, ADI_AFE_SEQ_STATE_FINISHED);
    adi_AFE_SeqStop(hAfe);
    adi_AFE_SetSeqState(hAfe, ADI_AFE_SEQ_STATE_IDLE);

   degC = ((int32_t)pADI_AFE->AFE_TEMP_SENSOR_RESULT - 3414) * 2 * 2 / 25;
    degC = (degC & 0x00000001)?(degC >> 1) + 1:degC >> 1;

   adi_AFE_PowerDown(hAfe);

   return degC;
}

 

When I try to run this code the processor gets stuck in the default handler for the bus-fault.

The sequences are the same as in the examples of the SDK, with plenty of wait cycles, so that the DMA has time to fill the fifo.

 

Any ideas, where the problem might come from?

 

Thank you, enpa

Outcomes