Hi KlausHi,
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
Again: you can not send data from microcontroler to MAX187. It is impossible. You have to accept this.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)
Klaus
/* 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);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?