pravin b
Member level 5
- Joined
- May 20, 2012
- Messages
- 85
- Helped
- 2
- Reputation
- 4
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Mumbai, India
- Activity points
- 2,083
Hello Friends,
I am trying SPI bit banging approach to interface ADC 0832 with AT89C51RD2. I have written following code for same purpose; however I am not able to develop logic for receiving a serial data from ADC 0832 and convert it into readable/usable byte to transmit received byte to PORT 2. Please find the attached code and my hardware simulation in proteus. All type of inputs/help are/is welcome.
Also, when I observe waveforms on oscilloscope at pin dout (P3.2) or MISO, I expect my immediate first bit is to be low (signifies mux settling time as per datasheet) and then 8 bits of data. But in my case I am receiving first bit low (mux settling time), 7 bits of data (I think so) and my 8th bit always remains high (I don’t know why!). Please help me to clear this doubt.
I am here by attaching my code and proteus simulation file & uvision project file for reference.
Thanks & regards,
Pravin B
I am trying SPI bit banging approach to interface ADC 0832 with AT89C51RD2. I have written following code for same purpose; however I am not able to develop logic for receiving a serial data from ADC 0832 and convert it into readable/usable byte to transmit received byte to PORT 2. Please find the attached code and my hardware simulation in proteus. All type of inputs/help are/is welcome.
Also, when I observe waveforms on oscilloscope at pin dout (P3.2) or MISO, I expect my immediate first bit is to be low (signifies mux settling time as per datasheet) and then 8 bits of data. But in my case I am receiving first bit low (mux settling time), 7 bits of data (I think so) and my 8th bit always remains high (I don’t know why!). Please help me to clear this doubt.
I am here by attaching my code and proteus simulation file & uvision project file for reference.
Thanks & regards,
Pravin B
Code:
#include<reg51.h>
sbit clk=P3^0;
sbit din=P3^1;
sbit dout=P3^2;
sbit cs=P3^3;
#define outport P2
void delay(unsigned int);
void adc_init();
void adc_read();
void main()
{
clk=0;
din=0;
dout=1;
outport=0x00;
while(1)
{
adc_init();
adc_read();
}
}
void delay(unsigned int count)
{
unsigned int i,j;
for(i=0;i<=count;i++)
for(j=0;j<=1300;j++);
}
void adc_init()
{
clk=0;
cs=1;
din=0;
delay(1);
clk=0;
cs=0;
din=1;
delay(1);
clk=1;
cs=0;
din=1;
delay(1);
clk=0;
cs=0;
din=1;
delay(1);
clk=1;
cs=0;
din=1;
delay(1);
clk=0;
cs=0;
din=0;
delay(1);
clk=1;
cs=0;
din=0;
delay(1);
clk=0;
cs=0;
din=0;
delay(1);
}
void adc_read()
{
int m, byte_in=0x01;
clk=1;
delay(1);
clk=0;
delay(1);
for(m=0;m<=7;m++)
{
clk=1;
cs=0;
delay(1);
clk=0;
delay(1);
byte_in=byte_in&dout;
byte_in=byte_in<<1;
delay(1);
}
outport=byte_in;
cs=1;
}