Continue to Site

### Welcome to our site!

#### Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Status
Not open for further replies.

#### mohanchandra

##### New Member
Hi

In this register, RDY (7 bit of STATUS REGISTER) bit always high.
while(1)
{
send_byte('C');
NextLine();
if(!(status&0x80))
break;
}
or
Problem: RDY_ADC pin(MISO) it is continously high. How we know completion of conversion

Anybody give me a solution for this problem and also if i get ADC value then
how i convert this adc to normal temparature.(V ref: 1.7v internal reference voltage).

Regards
Mohanchandra

I am trying to read the internal temparature value.Code is pasted below

#define CR_MODE_WR 0x08 //00001000
#define CR_CONFIG_WR 0x10 //00010000
#define CR_DATA_RD 0x5C //01011000//single conversion read
#define MODEREG_HIGH 0x20 //mode register Sinle conversion.64KHz internal clock
#define MODEREG_LOW 0x10
#define CONFIGREG_HIGH 0x10 //Configuration register,unipolar with 1.17 ref voltage,channel
#define CONFIGREG_LOW 0x86//temp sensor
#define CR_STATUSREG 0x40 //01000000
void main()
{
unsigned int i;
unsigned char ucCount=5,status;
serial_init();
Spi_Initialization();
while((ucCount--)>1)
{
P0 = 0x00; P1 = 0x00; P2 = 0x00; P3 = 0x00;
for(i=0;i<20000;i++);
P0 = 0xFF; P1 = 0xFF; P2 = 0xFF; P3 = 0xFF;
for(i=0;i<20000;i++);
send_byte('A');
}
//=========================Writing operation====================
CS_LOW; //enable
for(i=0;i<1000;i++);

CS_HIGH; //disable
for(i=0;i<10000;i++);
while(1)
{
CS_LOW; //enable
for(i=0;i<1000;i++);
/*while(1)
{
send_byte('C');
NextLine();
if(!(status&0x80))
break;
}*/
//Dispaly data in NextLine
//==========================================================

CS_HIGH; //Disable
send_byte('B');
NextLine(); //Dispaly data in NextLine
for(i=0;i<10000;i++);
}

}
//======================================================================

void serial_init()
{
TH1=0XFD; //Baud Rate 9600 FD
SCON=0X50; //Mode 1..8 bit data,..1 stop bit,..1 start bit
TR1=1;
RI=0;
TI=0;
}

{
while(TI==0);
TI=0;
}
void Spi_Initialization()
{
SPICON=0x3E; //ISPI WCOL SPE SPIM CPOL CPHA SPR1 SPR0

}
//Next line dispaly
void NextLine()
{
send_byte(0x0D);
send_byte(0x0A);
}
//Send data to ADC device throug SPI Communication Protocal
{
ISPI=0; //cler the flagh
SPIDAT=SPI_DATA; //load the 8 bit data to SPI data register
while(ISPI==0); //wait till flag will set
ISPI=0;

}
{
unsigned char ucData=0;
ISPI=0; //cler the flagh
SPIDAT=0; //load the 8 bit data to SPI data register
while(ISPI==0); //wait till flag will set
ucData=SPIDAT;
return(ucData);
}
//send bitwise digital data to serial
void send_bit_serial(unsigned char ucData)
{
unsigned char ucCount=0;
for(ucCount=0;ucCount<8;ucCount++)
{
if((ucData<<ucCount)&0x80)
send_byte(0x31);
else
send_byte(0x30);
}

}

Last edited:
Hey i know nothing of that controller but this seem ODD... why have 2 different SPI type functions. I think this one below should be fine but the one below it .. how does it send data through SPI?
Code:
void send_byte(unsigned char add)
{
while(TI==0);
TI=0;
}
void Spi_Initialization()
{
SPICON=0x3E; //ISPI WCOL SPE SPIM CPOL CPHA SPR1 SPR0

Code:
//Send data to ADC device throug SPI Communication Protocal
{
ISPI=0; //cler the flagh
SPIDAT=SPI_DATA; //load the 8 bit data to SPI data register
while(ISPI==0); //wait till flag will set
ISPI=0;

}

Maybe you should send data through the first one only?
also you are aware that :

is sending 8 bytes rights? (not bits)

Status
Not open for further replies.

Replies
6
Views
1K
Replies
11
Views
2K
Replies
1
Views
934
Replies
4
Views
2K
Replies
1
Views
957