+ Post New Thread
Results 1 to 13 of 13
  1. #1
    Junior Member level 1
    Points: 414, Level: 4

    Join Date
    Feb 2018
    Posts
    19
    Helped
    0 / 0
    Points
    414
    Level
    4

    SPI 12-Bit Serial ADCs

    Hello,

    I've been searching the internet for a long time trying to find a simple guide that explains about MAX187 ADC and how to interface it with 8051 but I couldn't.

    I have attached datasheet and timing diagram. I don't understand the timing diagram in the datasheet I am trying to know how master write data to Max187

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 78,516, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,931
    Helped
    3610 / 3610
    Points
    78,516
    Level
    68

    Re: SPI 12-Bit Serial ADCs

    Hi,

    Itīs almost straight forward SPI communication.

    "almost" because:
    * the EOC signaling
    * data direction is only one way: from ADC to microcontroller

    EOC signaling:
    The conversion is started by tying /CS = 0. then you have two options:
    * either wait for t_conv_Max ..
    * or (use a pullup at the MISO line) wait until MISO becomes "1"
    then start SPI transfer by sending 2 SPI "dummy" bytes out of the microcontroller. These 2 bytes will never reach the ADC, because MOSI is not wired. They are just needed to initiate 2 x 8 SCK cycles for data transmission via MISO.

    SPI usually is two way (full duplex) serial communication at the same time. But the ADC only outputs data (it getīs no input).
    You say: "how master write data to Max187". This simply never is the case. The microcontroller only reads data from the ADC.

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  3. #3
    Junior Member level 1
    Points: 414, Level: 4

    Join Date
    Feb 2018
    Posts
    19
    Helped
    0 / 0
    Points
    414
    Level
    4

    Re: SPI 12-Bit Serial ADCs

    Quote Originally Posted by KlausST View Post
    Hi,

    Itīs almost straight forward SPI communication.

    "almost" because:
    * the EOC signaling
    * data direction is only one way: from ADC to microcontroller

    EOC signaling:
    The conversion is started by tying /CS = 0. then you have two options:
    * either wait for t_conv_Max ..
    * or (use a pullup at the MISO line) wait until MISO becomes "1"
    then start SPI transfer by sending 2 SPI "dummy" bytes out of the microcontroller. These 2 bytes will never reach the ADC, because MOSI is not wired. They are just needed to initiate 2 x 8 SCK cycles for data transmission via MISO.

    SPI usually is two way (full duplex) serial communication at the same time. But the ADC only outputs data (it getīs no input).
    You say: "how master write data to Max187". This simply never is the case. The microcontroller only reads data from the ADC.

    Klaus
    Hi Klaus
    I am trying to understand data transmission procedure between PiC mcu and using SPI Max187

    There are four signals in the SPI bus

    Cs -> chip select
    Clk -> signal
    Din -> data input
    Dout -> data out

    What are the steps of communication if we want to send data from microcontroller to Max187



  4. #4
    Super Moderator
    Points: 78,516, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,931
    Helped
    3610 / 3610
    Points
    78,516
    Level
    68

    Re: SPI 12-Bit Serial ADCs

    Hi,

    Do this, step by step:
    * read about general SPI communicaton (general informations, not related to your microcontroller or ADC)
    * read microcontroller datasheet about SPI interface
    * search for "8051 SPI tutorial " and go through them. (there are almost 200 thousand hit on an internet search. Documents as well as videos)

    Regarding ADC:
    Iīve already told you about the ADC specialities. Everything else is SPI standard (as far as I can see).
    Wiring: microcontroller -- ADC
    /SS -- /CS
    SCK -- SCLK
    MISO --DOUT

    What are the steps of communication if we want to send data from microcontroller to Max187
    Again: you can not send data from microcontroler to MAX187. It is impossible. You have to accept this.

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  5. #5
    Junior Member level 1
    Points: 414, Level: 4

    Join Date
    Feb 2018
    Posts
    19
    Helped
    0 / 0
    Points
    414
    Level
    4

    Re: SPI 12-Bit Serial ADCs

    Quote Originally Posted by KlausST View Post
    Hi,

    Do this, step by step:
    * read about general SPI communicaton (general informations, not related to your microcontroller or ADC)
    * read microcontroller datasheet about SPI interface
    * search for "8051 SPI tutorial " and go through them. (there are almost 200 thousand hit on an internet search. Documents as well as videos)
    Klaus
    Steps to perform SPI communicaton

    1. The master outputs the clock signal:
    2. The master switches the SS/CS pin to a low voltage state, which activates the slave:
    3. The master sends the data one bit at a time to the slave along the MOSI line. The slave reads the bits as they are received:
    4. If a response is needed, the slave returns data one bit at a time to the master along the MISO line. The master reads the bits as they are received:



  6. #6
    Super Moderator
    Points: 78,516, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,931
    Helped
    3610 / 3610
    Points
    78,516
    Level
    68

    Re: SPI 12-Bit Serial ADCs

    Hi,

    Do you want to use integrated SPI periferal (hardware. I recommend this, if available) or do you wan to use SPI in bit bang mode (software)

    I already tried to explain in post#2:
    1) set /SS = /CS = 0
    2) wait until conversion finished
    3) sending a byte (or multiple) means:
    * the master generates clock
    * shifts data bits out at MOSI (Again: this line is not connected to the ADC. The ADC has no data_in line. Sending data to ADC is not possible)
    * shift data in from MISO. MISO is connected with ADC_DOUT. This way the microcontroller gets the ADC conversion result
    ...all at the same time.
    4) after transfer finished: set /SS = /CS = 1

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisement

        
       

  7. #7
    Super Moderator
    Points: 31,824, Level: 43
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    7,366
    Helped
    1727 / 1727
    Points
    31,824
    Level
    43

    Re: SPI 12-Bit Serial ADCs

    For general SPi communication your steps are correct, but for the MAX187 part the steps 3 and 4 are incorrect.

    3. master waits tCONV time.
    4. Master sends 17 SCK's pulses ADC data on MISO is sampled on rising edges of SCK on clock pulses 2-13 (from the diagram), MOSI is a don't care (send 0's if you have to send something)



  8. #8
    Super Moderator
    Points: 78,516, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,931
    Helped
    3610 / 3610
    Points
    78,516
    Level
    68

    Re: SPI 12-Bit Serial ADCs

    Hi,

    @ads-ee:
    * I`m quite sure the order of 1) and 2) in post#5 is not correct.

    * 17 SCK pulses is quite unusual, because SPI is byte oriented and thus SCK pulse count should be a multiple of 8.
    (just to keep on SPI standard and make software easier)
    But for sure one can do with 17 pulses... indeeed any number same or higher 13 will do.

    But with hardware SPI and also with SPI_bit_bang_functions the programmer should not care about generating SCK pulses (as long as he does not write the bit_bang_function on his own).
    Usually sendig a byte to the SPI_TX_buffer will automatically generate the pulses, and the shift_out and the shift_in process.

    Iīm not familiar with 8051, but I would be surprised if there was a big difference to other microcontrollers.

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  9. #9
    Super Moderator
    Points: 31,824, Level: 43
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    7,366
    Helped
    1727 / 1727
    Points
    31,824
    Level
    43

    Re: SPI 12-Bit Serial ADCs

    Klaus,

    Unless this is an 8051 embedded in a SoC microcontroller then the old 8051 didn't have anything like a SPI controller or any buffers. It's a micro from 1981 and only has some GPIO and a serial port interface. The OP will be restricted to bit-banging the SPI.

    I took the #1 as the micro controller supplies the SCK, not that they supply a continuous clock or when it generates the SCK (maybe I read too much into their description). I thought they had looked at the timing diagrams and saw how the clock was generated and when.

    #2 with CS=0 and waiting for the conversion is correct, I interpreted activates the slave as waiting for the conversion. I'm never sure if the problem with any given statement by posters is due to translating to English or just not understanding something. Maybe wrongly, I usually just assume they mangled their English translation.



  10. #10
    Super Moderator
    Points: 78,516, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,931
    Helped
    3610 / 3610
    Points
    78,516
    Level
    68

    Re: SPI 12-Bit Serial ADCs

    Hi,

    I agree with you.
    We don't know
    * which exact microcontroller the OP wants to use
    * whether he wants to use hardware (if available) or software SPI
    * which compiler
    * which language
    * which libraries
    * what programming background the OP has
    * what hardware background the OP has
    ...

    But he asks this specific questions:
    "I don't understand the timing diagram in the datasheet".
    "What are the steps of communication.."

    Thus I recommended to read some basic informations first,
    then go deeper to the specific requirements of both communication partner ICs.
    Then even deeper ... to the specific signals, which signal needs to be first and which signal needs to be next...

    A recommendation that fits to many technical problems: Start with learning the basics (independent of the used hardware and the used software), then step by step go deeper, to the ICs, the signals, the timing...

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  11. #11
    Advanced Member level 4
    Points: 8,225, Level: 21
    Achievements:
    7 years registered
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    1,325
    Helped
    269 / 269
    Points
    8,225
    Level
    21

    Re: SPI 12-Bit Serial ADCs

    hello,


    this code written in TurboC ..to get MAX187 ADC value
    could help you, even not written for a MCU

    Code:
    /* 24 10 94 */
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    typedef enum {FALSE,TRUE} bool;
    typedef unsigned char byte;
    typedef unsigned int word;
    
    struct REGPACK Rg;
    union REGS Re,Rs;
    
    char  *Tampon;
    word i,i1,j,j1,k,l,l1,m;
    int ADC;
    word far *RbT; /* Ram Bios Timer */
    long x,x1,x2 ;
    float Total,Moyenne;
    char c;
    static int table[]={2048,1024,512,256,128,64,32,16,8,4,2,1,0};
    
    void Delai_uS(word N)
    {
     word i,t;
     for (i=0;i0)
     {
     Delai_uS(10000);
     jjj--;
     }
    }
    
    void main (int argc,char *argv[])
    {
      clrscr();
      RbT= MK_FP (0x0040,0x006c);
      Tampon=(char *)malloc(300);
      if(argc>1)
      {
       argv[1]=strupr(argv[1]);
       k=argc-1;
       i=atoi(argv[1]);
       printf("\n Argument pass‚ : %s soit %04Xh",argv[1],i);
       sleep(1);
       if (i!=0) ADC=i;
       if ((i!=0x278)&&(i!=0x378))
    	{
    	 printf("\nTiens,tiens, ce n'est ni LPT1,ni LPT2 !");
    	 printf("\nAttention,PB !! ,be carefull !");
    	 sleep(2);
    	}
       }
       else
       {
       printf("\nPas d'argument dans la commande donc LPT1=888 par d‚faut.");
       ADC=888;
       }
      /* cs=1 */
      outportb(ADC,2);
      gotoxy(1,10);
      printf("TST ADC 12 bits  MAX187 sur port %3d (C) PF 24/10/94 \n",ADC);
      fflush(stdin);
      i=1;
      Total=0.0;
      Moyenne=0.0;
      do
      {
       l=0;
       /* cs=0 */
       outportb(ADC,0);
       /*attent fin de conversion */
       do
       {
    	  m=inportb(ADC+1) & 64;
    	}
       while(m==0);
       for (k=0;k<11;k++)
       {
    	/* one clock pulse */
    	outportb(ADC,1);
    	outportb(ADC,0);
    	j=inportb(ADC+1)& 64;
    	if (j==64) l=l+table[k]; else l=l;
       }
       /*cs=1 */
       outportb(ADC,2);
       Total=Total+l;
       if (i>100)
       {
       i=1;
       Moyenne=(Total/100.0);
       Total=0;
       }
      i++;
      gotoxy(1,11);
      printf(" i=%5d value=%08d Moyenne=%08.1f",i,l,Moyenne);
      if (kbhit()) c=(char)getch();
     }
     while (c!=27);
    outportb(ADC,0);
    }



    •   AltAdvertisement

        
       

  12. #12
    Super Moderator
    Points: 31,824, Level: 43
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    7,366
    Helped
    1727 / 1727
    Points
    31,824
    Level
    43

    Re: SPI 12-Bit Serial ADCs

    That code is not entirely in English (FYI posts are supposed to be in English)...because of this there is a char pointer name in this file that doesn't mean the same thing in English as it does in whatever language this was written in.

    Brand names of this char pointer include Kotex, Tampex, o.b., Playtex.



  13. #13
    Super Moderator
    Points: 261,317, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    45,654
    Helped
    13881 / 13881
    Points
    261,317
    Level
    100

    Re: SPI 12-Bit Serial ADCs

    The C code is helpful by clarifying that you don't need more than 12 clock pulses to read the ADC. In other regards it's not very instructive, doing a simple bit shift in an unbelievable complicated way and performing functions unrelated to the basic ADC readout.

    As already mentioned, generic 8051 has no SPI hardware, it needs to perform bit banging. It can be done in about 10 to 15 lines of C code.



--[[ ]]--