Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/24/08 09:28
Read: times


 
#156145 - AD7730
HI, i try to create connection with AT89C51 and AD7730. So i write this code. The data is send on the AD7730 but there is no respond.

Can you help me?

The SCLK is on port P3_3 and DIN/DOUT is on P3_4

/**
* \file main.c
* \brief First program in C for establish connection with PC via RS485 and test connection with AD7730
* \author Bertrand TUFFERY
* \author Pierre-Antoine HALOPEAU
* \version 0.5
* \date 19 juin 2008
*
*/

#include <REG52.H> /* special function register declarations */

/* for the intended 8051 derivative */
#include <stdio.h>

#include "main.h"

static unsigned char cpt_timer = 0; /* For using the ADC 7730 we must use this counter for delay*/

#ifdef MONITOR51 /* Debugging with Monitor-51 needs */

char code reserve [3] _at_ 0x23; /* space for serial interrupt if */

#endif /* Stop Exection with Serial Intr. */

/* is enabled */

int Status_register [8] = {0,0,1,0,0,0,0,0}; /* We write to the communication register
in order to read data in Status Register */


int Test_register [8] = {0,0,1,0,0,1,1,1}; /* We write to the communication register
in order to read data in Test Register */
/*------------------------------------------------

The main C function. Program execution starts

here after stack initialization.

------------------------------------------------*/

void main (void) {
/*------------------------------------------------

Setup the serial port for 1200 baud at 1MHz.

------------------------------------------------*/

#ifndef MONITOR51

SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */

TMOD = 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */

TH1 = 245; /* TH1: reload value for 1200 baud @ 1MHz */

TR1 = 1; /* TR1: timer 1 run */

TI = 1; /* TI: set TI to send first char of UART */

#endif

while (1) {

P1 ^= 0x40; /* Toggle P1.6 each time we print */
printf ("Allez les bleus\n"); /* Print "Allez les bleus" */
write_to_ADC (); /* We write to the communication register the data */
P3_5 = 1; /* We set the SCLK on high level */
read_from_ADC (); /* We read the data from the status register */
P3_5 = 1;
}

}


void read_from_ADC () {

int number_of_bits = 8; /* We read 8 bits from the AD7730*/
int tab [8]; /* We save the 8 bits in a tableau */
int counter_printer_data = 0; /* This counter is used to print the data to PC*/

printf(" Je suis dans la lecture du registre ADC \n"); //TEST
if (P3_3 == 1) {
P3_5 = 0;
printf(" Je suis dans la lecture \n"); // TEST
tab[number_of_bits] = P3_4; /* We save the MSB of status register */

while (number_of_bits !=0 ) {
if (++cpt_timer == 1) {
cpt_timer = 0;

P3_5 = 1;

number_of_bits--;
}

if (++cpt_timer == 1) {

cpt_timer = 0;

P3_5 = 0;

tab[number_of_bits] = P3_4;


}



}
}

for (counter_printer_data=0;counter_printer_data<8;counter_printer_data++) {
printf (" %i \n",tab[counter_printer_data]); /*We send on the RS485, the data which it come from AD7730 */
/*In this case we read the status register */

}
}

void write_to_ADC () {



int number_of_bits = 0;


P3_3 = 0;



if (++cpt_timer == 1) {

cpt_timer = 0;

P3_4 = Status_register[7-number_of_bits];

number_of_bits++; /* This bit is the bit for WE, write enable to the communication register */

}

while (number_of_bits <8) {



if (++cpt_timer == 1) {
cpt_timer = 0;

P3_3 = 1; /* We put SCLK on high level */

}

if (++cpt_timer == 1) {

cpt_timer = 0;

P3_3 = 0 ; /* We put SCLK on low level*/

}


if (++cpt_timer == 1) {

cpt_timer = 0;

P3_4 = Status_register[7-number_of_bits] ; /* We send the second bit in write mode*/

number_of_bits++;

}

}


}


List of 6 messages in thread
TopicAuthorDate
AD7730            01/01/70 00:00      
   CS#            01/01/70 00:00      
   How to post source code            01/01/70 00:00      
      also            01/01/70 00:00      
   AD7730 code            01/01/70 00:00      
      it is all in the datasheet            01/01/70 00:00      

Back to Subject List