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 Answer
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.
-
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, 2021 at 16:43
-
1T_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.– MajenkoJan 12, 2021 at 16:47
-