0

I'm looking for the Library of the ADC MCP33121 for Arduino UNO or functional code, I don't have enough tools for testing so I'd like to get some code already tested. I appreciate any help. Thanks... Josh

1
  • There don't seem to be such a library for that specific chip. At least I found none when googling for it. You might need to write the code yourself.
    – chrisl
    Jan 12 at 16:23
2

You don't really need a library for that chip. You just do a pair of SPI transfers with the CS pin low.

For example:

digitalWrite(pinCS, LOW);
uint8_t msb = SPI.transfer(0xFF);
uint8_t lsb = SPI.transfer(0xFF);
digitalWrite(pinCS, HIGH);

uint16_t val = (((uint16_t)msb << 8) | lsb);
val = val >> 2; // For 14 bit devices shift it twice. For 12 bit do it 4 times.
3
  • Thanks for your answer, I was checking the datasheet and looking at the code that you provide, the digitalWrite(pinCS, LOW)... until the digitalWrite(pinCS, HIGH), it neglects the timing aspect. I mean the datasheet provides some timing for acquisition and conversion so, should I have to worry about that timing? Jan 12 at 16:43
  • 1
    T_CNV is at worst 1300ns. That's only 20 clock cycles on a 16MHz Arduino. By the time you get round to sampling again that time will have passed. The T_EN is a mere 10ns. That's a sixth of the length of one clock cycle. You would have to be doing something really bizarre with your Arduino to even come remotely close to needing to even think about the possibility of timing being an issue.
    – Majenko
    Jan 12 at 16:47
  • Thanks for sharing. Jan 12 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.