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.

Serial ADC AD7321 w/ 89c51 coding problem

Status
Not open for further replies.

Ashkar

Full Member level 2
Joined
Sep 16, 2010
Messages
131
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
India
Activity points
2,207
#include<reg51.h>
sbit CS=P2^0;
sbit SCLK=P2^1;
sbit DIN=P2^2;
sbit DOUT=P2^3;

void delay()
{ int i;
for(i=0;i<1200;i++)
for(i=0;i<1200;i++)
{}
}


void main()
{

unsigned char config= Value comes here ; //control register value(
unsigned char x,z,out;
while (1)

{

z=config;
CS=0;
for(x=0;x<17;x++)
{
SCLK=0;
DIN=z;
// delay();
SCLK=1;
//delay();
z=z<<1;
}
CS=1;
SCLK=0;
CS=0;
// delay();


for(x=0;x<17;x++)
{
SCLK=1;
//delay();
SCLK=0;
//delay();
out=DOUT;
z=z<<1;
}
CS=1;
//data out at "OUT" variable;


}
}
Compiler used KEIL and Mcu PHILIPS 89c51rd2
Please help me to correct my code for ad7321
 

hi ashkar,

i understand u r trying to do spi bit banging. i suggest u to read SPI protocol first. and please recheck the Din which u have used is for data
receive or transmit. usually it will be used to receive data. pls post ur circuit diagram for better clarity..

finally when u do bit banging, u have to transmit data bit by bit. dont assign z=config. i think u are keeping the clock low and trying to transmit complete byte, which will not happen. when u pulse a clock only one bit can be transmitted.

thanks and regards,
karthikkr

- - - Updated - - -

keil has lot of examples related to SPI bit banging.. please refer them too
 

Hi ashkar

pls try to post your circuit diagram for better clarification

hear you are assigning the adc byte value by z=config, but u have to transmit that it bit by bit only....
 

Why use bit banging. simple use hardware clock SPI if available onchip. I think it is available on this version of NXP uC.
Also enable an SPI Interrupt, this makes code simple and compact.
Bit banging is not a good solution when considering accuracy and timing neither for I2C nor for SPI.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top