Raspberry pi e MAX1202 MAX1203 MAX1204

With this program you can use Maxim's 8 input analog digital converters types MAX1202 MAX1203, with 12 bit resolution and MAX1204 with 10 bit resolution, between the spi_bcm2708's SPI interface on the Raspberry pi.
The ic power supply is 5V, but the SPI interfaces pin could work at different voltages, you can use the 3,3V from P1 Raspberry's port and input it on the VL chip pin, then the SPI logic work at 3,3V and yo haven't any problem interfacing the chip with Raspberry pi.
Tryed with clock speed of 2MHz and below.
Source code from Github
Tested with 2013-09-10-wheezy-raspbian linux.

To enable the SPI interface you must modify the file
/etc/modprobe.d/raspi-blacklist.conf
commenting this line
#blacklist spi-bcm2708

If you want run the program without root privileges you can execute these command

sudo groupadd spi
sudo usermod -a -G spi pi
sudo su
echo 'DEVPATH=="/devices/platform/bcm2708_spi.0/spi_master/spi0/spi0.0/spidev/spidev0.0", GROUP="spi"' > /etc/udev/rules.d/99-spi.rules
echo 'DEVPATH=="/devices/platform/bcm2708_spi.0/spi_master/spi0/spi0.1/spidev/spidev0.1", GROUP="spi"' >> /etc/udev/rules.d/99-spi.rules
reboot

that add the spi group and add to it the pi user.
The last two lines add a udev rule that assign the spi group to the SPI bus.
In that manner you can run the program
./raspandmax
without sudo



Schematic


Some samples


pi@raspberrypi:~/develop/spi$ sudo ./raspandmax
3526

Verbose mode

pi@raspberrypi:~/develop/spi$ sudo ./raspandmax -v
device: /dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
input port 0
chip MAX1202 or MAX1203
unipolar mode
single ended mode
external clock mode
transmit byte 143
First byte: 0
Second byte 110
Third byte 40
Analog read: 3525
pi@raspberrypi:~/develop/spi$ 

Options

sudo ./raspandmax -h

Usage: ./raspandmax [-4Dscibkvnd]

 Maxim MAX1202 MAX1203 MAX1204 SPI adc utility
 http://www.panu.it/raspandmax/

 Usage:
 -4 --max1204 select max1204 10 bit adc, default is max1202/3 12 bit
 -D --device device to use (default /dev/spidev0.0)
 -s --speed SPI bus speed (Hz), default 500000
 -c --chipsel disable chipsel at read end, default don't disable
 -i --input chose input channel 0 to 7, default 0
 -b --bipolar set to bipolar mode, default unipolar
 -k --clock set internal clock mode, default external
 -v --verbose print extra info usefoul for debug
 -n --newline suppress new line at non verbose output end
 -d --diff set to differential mode,
      default is single ended, see table
      for input channel selection:

       ---------------
      | Input l + | - |
       ---------------
      |   0   | 0 | 1 |
       ---------------
      |   1   | 2 | 3 |
       ---------------
      |   2   | 4 | 5 |
       ---------------
      |   3   | 6 | 7 |
       ---------------
      |   4   | 1 | 0 |
       ---------------
      |   5   | 3 | 2 |
       ---------------
      |   6   | 5 | 4 |
       ---------------
      |   7   | 7 | 6 |
       ---------------
 Output:
 0 to 4095 for MAX1202 and MAX1203
 0 to 1203 for max 1204


Long hardware test


pi@raspberrypi:~/develop/spi$ for label in {1..1000}; do echo -n " ${label} " ;sudo ./raspandmax -4ns 2000000 ; echo -n ", "; done; echo 
 1 881,  2 881,  3 879,  4 881,  5 881,  6 881,  7 880,  8 880,  9 881,  10 879,  11 880,  12 881,  13 881,
 14 881,  15 879,  16 881,  17 881,  18 881,  19 880,  20 878,  21 881,  22 880,  23 880,  24 881,  25 881,
 26 880,  27 881,  28 881,  29 881,  30 880,  31 881,  32 880,  33 880,  34 881,  35 879,  36 881,  37 881,
 38 881,  39 881,  40 881,  41 880,  42 881,  43 880,  44 881,  45 881,  46 881,  47 881,  48 881,  49 882, 
 50 881,  51 880,  52 880,  53 880,  54 881,  55 880,  56 879,  57 881,  58 881,  59 881,  60 880,  61 879, 
 62 881,  63 881,  64 881,  65 881,  66 880,  67 880,  68 880,  69 881,  70 881,  71 881,  72 880,  73 881, 
 74 881,  75 880,  76 881,  77 881,  78 879,  79 881,  80 881,  81 881,  82 880,  83 881,  84 881,  85 881, 
 86 881,  87 881,  88 880,  89 881,  90 879,  91 880,  92 881,  93 881,  94 880,  95 879,  96 881,  97 881, 
 98 880,  99 881,  100 878,  101 881,  102 881,  103 881,  104 880,  105 880,  106 880,  107 881,  108 880, 
 109 881,  110 881,  111 880,  112 880,  113 881,  114 881,  115 882,  116 881,  117 879,  118 880,  119 881, 
 120 881,  121 881,  122 882,  123 881,  124 881,  125 881,  126 881,  127 881,  128 881,  129 880,  130 881, 
 131 879,  132 880,  133 880,  134 881,  135 881,  136 879,  137 881,  138 880,  139 881,  140 881,  141 878, 
 142 881,  143 881,  144 880,  145 881,  146 879,  147 881,  148 881,  149 880,  150 881,  151 878,  152 880, 
 153 881,  154 880,  155 881,  156 882,  157 880,  158 880,  159 881,  160 881,  161 878,  162 880,  163 881, 
 164 881,  165 881,  166 879,  167 880,  168 881,  169 880,  170 880,  171 882,  172 881,  173 880,  174 881, 
 175 880,  176 880,  177 881,  178 881,  179 881,  180 881,  181 880,  182 881,  183 881,  184 881,  185 880, 
 186 879,  187 880,  188 880,  189 881,  190 881,  191 879,  192 881,  193 881,  194 881,  195 881,  196 881, 
 197 881,  198 881,  199 881,  200 881,  201 879,  202 881,  203 881,  204 880,  205 880,  206 881,  207 881, 
 208 881,  209 881,  210 881,  211 878,  212 881,  213 881,  214 881,  215 881,  216 880,  217 881,  218 881, 
 219 880,  220 879,  221 881,  222 881,  223 882,  224 881,  225 879,  226 881,  227 881,  228 880,  229 881, 
 230 879,  231 881,  232 881,  233 880,  234 880,  235 880,  236 880,  237 880,  238 881,  239 881,  240 879, 
 241 881,  242 881,  243 880,  244 881,  245 879,  246 881,  247 881,  248 880,  249 880,  250 881,  251 880, 
 252 880,  253 881,  254 881,  255 881,  256 881,  257 881,  258 881,  259 881,  260 878,  261 881,  262 881, 
 263 880,  264 881,  265 879,  266 881,  267 881,  268 881,  269 880,  270 881,  271 880,  272 881,  273 880, 
 274 881,  275 881,  276 881,  277 881,  278 881,  279 881,  280 879,  281 880,  282 881,  283 881,  284 881, 
 285 880,  286 880,  287 881,  288 881,  289 880,  290 881,  291 881,  292 880,  293 881,  294 881,  295 881, 
 296 880,  297 881,  298 880,  299 880,  300 880,  301 881,  302 880,  303 881,  304 879,  305 881,  306 881, 
 307 881,  308 880,  309 880,  310 881,  311 881,  312 882,  313 881,  314 881,  315 880,  316 880,  317 881, 
 318 881,  319 879,  320 881,  321 881,  322 881,  323 881,  324 880,  325 880,  326 880,  327 881,  328 880, 
 329 879,  330 881,  331 880,  332 880,  333 881,  334 881,  335 881,  336 881,  337 881,  338 881,  339 880, 
 340 881,  341 881,  342 881,  343 881,  344 880,  345 881,  346 880,  347 880,  348 881,  349 879,  350 880, 
 351 881,  352 881,  353 881,  354 881,  355 881,  356 881,  357 881,  358 880,  359 881,  360 881,  361 880, 
 362 881,  363 881,  364 879,  365 880,  366 881,  367 880,  368 881,  369 882,  370 881,  371 881,  372 881, 
 373 881,  374 880,  375 881,  376 881,  377 880,  378 881,  379 881,  380 881,  381 880,  382 880,  383 879, 
 384 880,  385 881,  386 881,  387 881,  388 881,  389 881,  390 881,  391 880,  392 881,  393 881,  394 881, 
 395 881,  396 881,  397 881,  398 879,  399 881,  400 880,  401 880,  402 881,  403 882,  404 881,  405 881, 
 406 881,  407 881,  408 880,  409 880,  410 881,  411 881,  412 881,  413 879,  414 881,  415 880,  416 880, 
 417 881,  418 880,  419 881,  420 881,  421 881,  422 881,  423 881,  424 881,  425 881,  426 881,  427 880, 
 428 881,  429 881,  430 881,  431 881,  432 881,  433 881,  434 881,  435 880,  436 881,  437 881,  438 880, 
 439 881,  440 881,  441 881,  442 880,  443 880,  444 880,  445 881,  446 881,  447 881,  448 879,  449 881, 
 450 881,  451 880,  452 881,  453 882,  454 881,  455 881,  456 881,  457 881,  458 880,  459 881,  460 879, 
 461 880,  462 881,  463 880,  464 880,  465 879,  466 881,  467 881,  468 881,  469 881,  470 880,  471 881, 
 472 881,  473 881,  474 881,  475 880,  476 880,  477 880,  478 881,  479 881,  480 881,  481 881,  482 879, 
 483 880,  484 881,  485 882,  486 881,  487 880,  488 881,  489 881,  490 880,  491 880,  492 880,  493 880, 
 494 881,  495 881,  496 880,  497 880,  498 881,  499 881,  500 881,  501 881,  502 879,  503 881,  504 881, 
 505 880,  506 881,  507 881,  508 880,  509 881,  510 881,  511 881,  512 881,  513 881,  514 881,  515 880, 
 516 882,  517 878,  518 881,  519 881,  520 880,  521 881,  522 880,  523 881,  524 880,  525 880,  526 880, 
 527 879,  528 880,  529 881,  530 880,  531 880,  532 879,  533 881,  534 881,  535 881,  536 881,  537 880, 
 538 881,  539 878,  540 881,  541 880,  542 881,  543 882,  544 881,  545 881,  546 880,  547 880,  548 881, 
 549 881,  550 878,  551 881,  552 880,  553 880,  554 881,  555 878,  556 881,  557 881,  558 881,  559 881, 
 560 879,  561 881,  562 880,  563 880,  564 880,  565 879,  566 880,  567 881,  568 880,  569 881,  570 881, 
 571 881,  572 881,  573 882,  574 881,  575 881,  576 881,  577 881,  578 881,  579 881,  580 879,  581 880, 
 582 880,  583 881,  584 880,  585 881,  586 881,  587 881,  588 882,  589 880,  590 881,  591 881,  592 881, 
 593 880,  594 881,  595 881,  596 880,  597 880,  598 880,  599 880,  600 880,  601 880,  602 881,  603 880, 
 604 881,  605 879,  606 881,  607 881,  608 880,  609 880,  610 879,  611 881,  612 881,  613 881,  614 881, 
 615 878,  616 881,  617 880,  618 881,  619 873,  620 881,  621 880,  622 878,  623 880,  624 880,  625 880, 
 626 880,  627 877,  628 881,  629 880,  630 881,  631 881,  632 880,  633 881,  634 881,  635 880,  636 881, 
 637 881,  638 880,  639 881,  640 881,  641 881,  642 878,  643 881,  644 881,  645 881,  646 881,  647 881, 
 648 881,  649 880,  650 881,  651 881,  652 879,  653 881,  654 881,  655 880,  656 880,  657 879,  658 881, 
 659 881,  660 881,  661 881,  662 880,  663 880,  664 878,  665 881,  666 880,  667 881,  668 881,  669 879, 
 670 880,  671 881,  672 880,  673 880,  674 880,  675 880,  676 881,  677 881,  678 881,  679 881,  680 881, 
 681 881,  682 880,  683 881,  684 881,  685 881,  686 880,  687 881,  688 881,  689 878,  690 880,  691 881, 
 692 881,  693 881,  694 881,  695 881,  696 881,  697 881,  698 880,  699 881,  700 881,  701 881,  702 880, 
 703 881,  704 881,  705 881,  706 881,  707 881,  708 879,  709 880,  710 880,  711 881,  712 880,  713 880, 
 714 880,  715 880,  716 881,  717 881,  718 881,  719 881,  720 880,  721 881,  722 881,  723 880,  724 880, 
 725 881,  726 881,  727 881,  728 880,  729 881,  730 880,  731 880,  732 881,  733 880,  734 880,  735 880, 
 736 881,  737 881,  738 880,  739 881,  740 880,  741 881,  742 880,  743 880,  744 881,  745 881,  746 880, 
 747 880,  748 880,  749 880,  750 881,  751 881,  752 881,  753 878,  754 880,  755 881,  756 880,  757 881, 
 758 879,  759 881,  760 881,  761 881,  762 881,  763 879,  764 881,  765 880,  766 880,  767 881,  768 879, 
 769 881,  770 881,  771 881,  772 881,  773 879,  774 881,  775 881,  776 881,  777 881,  778 879,  779 880, 
 780 880,  781 880,  782 881,  783 878,  784 881,  785 880,  786 881,  787 881,  788 880,  789 880,  790 879, 
 791 880,  792 881,  793 881,  794 880,  795 881,  796 880,  797 880,  798 881,  799 881,  800 882,  801 881, 
 802 881,  803 881,  804 880,  805 881,  806 881,  807 880,  808 881,  809 880,  810 881,  811 881,  812 879, 
 813 881,  814 881,  815 880,  816 881,  817 880,  818 881,  819 881,  820 880,  821 881,  822 880,  823 881, 
 824 881,  825 881,  826 881,  827 879,  828 880,  829 881,  830 881,  831 881,  832 879,  833 881,  834 881, 
 835 881,  836 880,  837 880,  838 881,  839 881,  840 881,  841 881,  842 879,  843 880,  844 880,  845 880, 
 846 881,  847 881,  848 881,  849 881,  850 882,  851 880,  852 881,  853 881,  854 880,  855 882,  856 881, 
 857 880,  858 881,  859 881,  860 881,  861 881,  862 881,  863 880,  864 880,  865 882,  866 880,  867 880, 
 868 880,  869 881,  870 881,  871 881,  872 881,  873 881,  874 879,  875 881,  876 880,  877 880,  878 881, 
 879 880,  880 880,  881 880,  882 881,  883 880,  884 880,  885 881,  886 881,  887 881,  888 881,  889 879, 
 890 881,  891 881,  892 881,  893 880,  894 881,  895 879,  896 880,  897 881,  898 880,  899 881,  900 881, 
 901 880,  902 882,  903 881,  904 880,  905 881,  906 881,  907 880,  908 881,  909 880,  910 880,  911 881, 
 912 880,  913 880,  914 881,  915 881,  916 880,  917 880,  918 880,  919 881,  920 881,  921 881,  922 882, 
 923 881,  924 880,  925 881,  926 880,  927 882,  928 880,  929 881,  930 880,  931 881,  932 882,  933 880, 
 934 881,  935 880,  936 881,  937 879,  938 881,  939 880,  940 881,  941 881,  942 882,  943 881,  944 881, 
 945 881,  946 880,  947 881,  948 880,  949 881,  950 880,  951 881,  952 881,  953 881,  954 881,  955 880, 
 956 880,  957 881,  958 880,  959 881,  960 880,  961 880,  962 880,  963 881,  964 881,  965 878,  966 879, 
 967 881,  968 881,  969 881,  970 880,  971 879,  972 881,  973 881,  974 881,  975 881,  976 879,  977 880, 
 978 881,  979 880,  980 881,  981 880,  982 881,  983 880,  984 882,  985 881,  986 880,  987 881,  988 880, 
 989 880,  990 881,  991 879,  992 881,  993 881,  994 880,  995 880,  996 880,  997 881,  998 881,  999 881, 
 1000 881, 
pi@raspberrypi:~/develop/spi$ 



THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.