Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SPI 12-Bit Serial ADCs

Status
Not open for further replies.

ansh11

Member level 4
Joined
Feb 27, 2018
Messages
71
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
659
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
 

Attachments

  • Timing diagram.jpg
    Timing diagram.jpg
    82.7 KB · Views: 138

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,

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
 

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
 

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:
 

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
 

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)
 

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
 

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.
 

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
 

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 <stdio.h>
#include <alloc.h>
#include <Dos.h>
#include <Bios.h>
#include <conio.h>
#include <fcntl.h>
#include <graphics.h>
#include <string.h>

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;i<N;i++)
  {
   for (t=0;t<4;t++);
  }
}

void Delai(int jjj)
{
 while (jjj>0)
 {
 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);
}
 

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.
 

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.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top