1

I have tried debugging for a couple days with no luck, so this question is a cry for help.

I am trying to configure an external ADC (MCP3464 datasheet). The ADC uses SPI communication and I am getting a response from it when I set the delay to 1000ms. If I lower this below 100ms, the ADC does not update and prints the last value stored in the ADC register.

Here is the relevant part of the code, although I have attached the whole file in case you would like to check command bytes etc.

void adcSimple(){

    unsigned char convStatus;
    uint16_t adcData;    
    // chip Select pin LOW to read/write to ADC
    digitalWrite(adcChipSelectPin,LOW); 
    convStatus = SPI.transfer(readConversionData);
    // extracts remaing bytes and append to adcData 16 bit integer (15bits plus sign)
    adcData = SPI.transfer(0);
    adcData <<= 8;
    adcData |= SPI.transfer(0);
    // chip select pin hgih to stop read/write to ADC
    digitalWrite(adcChipSelectPin, HIGH);
    
    // start next conversion
    writeData(&startConversionFastCmd, 1);
    
    Serial.println(adcData);
}


void setup(){
  Serial.begin(115200);
  while (! Serial); 
  spiInit();
  adcInit();
  // set ADC Multiplexer to channel 0 
  writeData(&muxRegisters[0][0], 2);
  delay(1000);
}

void loop(){
  adcSimple();
  delay(1000);
}

The adcSimple() function reads the ADC register address and appends it to the 16 bit adcData variable.

writeData(&startConversionFastCmd, 1);

The line above then restarts the ADC conversion (not the whole device) which is required to update the ADC register. For some reason this does not update the ADC register when there is insufficient delay in the loop.

  // Check the data ready bit
  if ((convStatus & 0x04) == 0x04)
  {
     Serial.println("ADC not ready!!!");

  }

I have run a test on convStatus, and this shows the ADC is not ready when the delay is short (around 100ms). I just don't understand why it takes so long (1000ms is equivalent to light years when running on 6MHz clock!)

Any suggestions would be greatly appreciated. Maybe someone has had a similar problem before? Thanks, Will

5
  • 1
    "attached the whole file", I seem to have missed it. Where does writeData come from? Or adcInit?
    – timemage
    Aug 11, 2021 at 18:26
  • SOLVED: I lowered the oversampling rate (See table 5-6 of datasheet) and thus increased the data rate. Thanks for the response timemage Aug 12, 2021 at 8:32
  • No problem. Unfortunately now you have an unanswered question that's unlikely to be answered. If you wanted, you could flesh-out your answer-in-comment and post it as an answer proper. With only your own answer, you have some latitude, in my opinion anyway, in editing the question to match. Basically, you can leave behind a useful question/answer combo for a future reader with an Arduino and an MCP3464.
    – timemage
    Aug 12, 2021 at 13:53
  • Can you please share the file because I'm facing writing and reading register for the same adc. Also I'm not able to confirm that spi is initialized or not
    – Sanketa
    Jun 8, 2022 at 5:04
  • I have added the MCP3464 library/driver to github - github.com/WillPowellUk/MCP3464-ADC Jun 10, 2022 at 19:31

0

Browse other questions tagged or ask your own question.