Pachi
Newbie level 3
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 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)