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.

CS5460A to 8051/8052: How to read data

Status
Not open for further replies.

Pachi

Newbie level 3
Joined
Jan 20, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Bangalore
Activity points
1,352
Hello

I am facing a problem interfacing the Cirrus CS5450A to Atmel 89C51/ 89C52 microcontroller.

I want to know how to read data from the 5460A. The SCK, SDO, SDI pins are being read through T0, T1 and WR pins (Port 3 pins 4,5,6). I went through the datasheet of 5460 and tried some code, but the bytes read are some arbitrary value.
Following is the code:



void read_data (void)
{
write_to_register(0xE8, 0xFF, 0xFF, 0xFF); //Start conv, Nop, Nop, Nop
write_to_register(0xFF, 0xFF, 0xFF, 0xFE); //Sync1, Sync1,Sync1,Sync0
read_register(0x0E); //Read Current Register
}

void write_to_register(char command,char low,char mid,char high)
{
transfer_byte(command);
transfer_byte(high);
transfer_byte(mid);
transfer_byte(low);
return;
}

void read_register(char command)
{
transfer_byte(command);
high_byte = recieve_byte(); /*Receive Bytes*/
mid_byte = recieve_byte();
low_byte = recieve_byte();
return;
}


void transfer_byte(char number)
{
unsigned int q, x, b[8];
for(q = 7; q != 0; q--) //convert to binary
{
x = number / (1 << q);
number = number - x * (1 << q);
b[q]=x;
}
SCLK=0;

for (q=7; q!=0; q--)
{
SDI= b[q]; //place bit to transmit
SCLK=1; SCLK=0; //pulse the clock
}
SDI=1;
return;
}


char recieve_byte(void)
{
unsigned int i;
unsigned char x[8], sync[8]="11111110";
SDI=1;
for (i=0; i<8; i++)
{
x=SDO; //receive bit
SDI= sync; //datasheet says Sync0 should be strobed on SDI
//while reading from SDO

SCLK=1; SCLK=0; //pulse the clock
}
return x;
}


Added after 20 minutes:

The output is:
high_byte= mid_byte= low_byte =10

Also, the write_to_register function calls are making no effect (same output without them). Without read_register, the values are 0 each, so read_register does work, but not properly (it always shows these values no matter what the current/voltage read is)
 

I read through that post and implemented the initializations. but there still seems to be a problem. the 24 bit data read is still 00 00 00. Here's the modified code.

void begin()
{
unsigned int i;
RESET=0; //initial reset
SDelay(100);
RESET=1;

write_to_register(0x5E, 0x00, 0x00, 0x01); //status reg= 000001
write_to_register(0x40, 0x00, 0x00, 0x04); //config reg= 000004
write_to_register(0x4A, 0x00, 0x00, 0x32); //cycle count=000032
write_to_register(0x78, 0x00, 0x00, 0x08); //control reg=000008
write_to_register(0x74, 0x80, 0x00, 0x00); //mask reg= 800000
write_to_register(0xE8, 0xFF, 0xFF, 0xFF); //start conv, nop, nop, nop
write_to_register(0xFF, 0xFF, 0xFF, 0xFE); //nop, nop, nop, nop

read_register(0x0E); //read inst current reg
SDelay(200); //delay

for (i=0;i<50;i++)
{
P2=0xFF; led1=0; P0=Display((high_byte>>4)& 0x0F); //Display High
SDelay(300);
P2=0xFF; led2=0; P0=Display((high_byte)& 0x0F);
SDelay(300);

P2=0xFF; led3=0; P0=Display((mid_byte>>4)& 0x0F); //Display Mid
SDelay(300);
P2=0xFF; led4=0; P0=Display((mid_byte)& 0x0F);
SDelay(300);

P2=0xFF; led5=0; P0=Display((low_byte>>4)& 0x0F); //Display Low
SDelay(300);
P2=0xFF; led6=0; P0=Display((low_byte)& 0x0F);
SDelay(300);
}
return;
}

void write_to_register(char command,char low,char mid,char high)
{
transfer_byte(command); //Transfer command followed by 24 bit data
transfer_byte(high);
transfer_byte(mid);
transfer_byte(low);
return;
}


void read_register(char command)
{
transfer_byte(command);
high_byte = recieve_byte(); //Receive Bytes
mid_byte = recieve_byte();
low_byte = recieve_byte();
return;
}

void transfer_byte(char number)
{
unsigned int i;
for (i=0; i<8; i++)
{
if (number & 0x80) SDI=1; //bit to be transferred is put on SDI
else SDI=0;

SDelay(100); //delay
SCLK=1; SDelay(100); SCLK=0; SDelay(100); //pulse clock

number = number<<1; //next bit
}
return;
}


char recieve_byte(void)
{
unsigned int i;
unsigned char x, sync=0xFE;
SDI=1;
for (i=0; i<8; i++)
{
x=x|SDO; //bit recieced from SDO is stored
x=x <<1;

if(sync &0x80) SDI=1; //strobing nop on SDI while reading
else SDI=0; //as per 5460 datasheet
sync= sync<<1;

SDelay(100); //delay
SCLK=1; SDelay(100); SCLK=0; SDelay(100); //pulse clock
}
return x;
}

Added after 26 minutes:

I also tried writing to the register im reading.

write_to_register(0x4E, 0xFF, 0xFF, 0xFF); //write instead of start conv, nop, nop, nop
write_to_register(0xFF, 0xFF, 0xFF, 0xFE); //nop, nop, nop, nop

no change.
 

I hav not gone through ur code, but just try it with pins other thanTo & T1 of controller.
 

The circuit is hardwired on a PCB. cant change it. i think its a software problem.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top