I have did the (modified and interface)circuit to connect an Arduino Ethernet and the ADAU1701.
Currently I am trying to configure the SPI communication in Arduino script but not success yet.
Could you guys please guide me how to solve my problem with the reference code and circuit as below.
Thanks and regards,
kal
#include <SPI.h>
int ETHCS = 10;
int data0 = 0;
int data1 = 0;
int data2 = 0;
void setup() {
SPI.begin();
pinMode(ETHCS, OUTPUT);
pinMode(9, OUTPUT);
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
digitalWrite(ETHCS,HIGH);
digitalWrite(9,LOW);
Serial.begin(57600);
}
void loop(){
//pull low clatch three times
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
//end pull low clatch three times
SPI.transfer(0x01);//chip address and read bit
SPI.transfer(0x08); //MSB address
SPI.transfer(0x1A); //LSB address
SPI.transfer(0x00); //MSB data
SPI.transfer(0x2A); //LSB data
data0 = SPI.transfer(0x00); //store read result in data0
data1 = SPI.transfer(0x00); //store read result in data1
data2 = SPI.transfer(0x00); //store read result in data2
digitalWrite(ETHCS, HIGH);
Serial.print(data0,HEX);
Serial.print(data1,HEX);
Serial.println(data2,HEX);
}
I'm not sure why the MOSI and CS resistor circuit. Normally those would be a direct connection.
If you are trying to communicate with the ADAU1701, why are you toggling the w5100 CS line? That is D10 (ETHCS). Which Arduino pin is the ADAU1701 CS line? Is that D9? If so, you should be using that instead of D10 (ETHCS).
I agree with SurferTim that the SPI wiring seems a bit strange.
I don't have one of these chips but your program does not make sense to me. What is on pin 9?
Your pulsing the SS pin low three time to change from I2C to SPI and then going on to write commands but do you maybe need to add another HIGH/LOW toggle to finish the SPI setup?
You then going on to read address 0x081A (Data Capture 0) that is a 16 bit register but you look to be discarding the result with writing the next two bytes and then reading the next 3 bytes that are 'Data Capture 1' and half of 'DSP core control'.
Also in the manual it states...
CONTROL REGISTERS SETUP
The following registers must be set as described in this section
to initialize the ADAU1701. These settings are the basic minimum
settings needed to operate the IC with an analog input/output of
48 kHz. More registers may need to be set, depending on the
application. See the RAMs and Registers section for additional
settings.
DSP Core Control Register (Address 2076)
Set Bits[4:2] (ADM, DAM, and CR) each to 1.
DAC Setup Register (Address 2087)
Set Bits[0:1] (DS[1:0]) to 01.
Thanks guys for the quick and informative reply. I hope we can continue discussing on this...
I'm not sure why the MOSI and CS resistor circuit. Normally those would be a direct connection.
The circuit was built so, since the Arduino operate at 5 Volts likewise its signal. Meanwhile the DSP board likewise the DSP processor chip operate at 3.3 Volts. If I am wrong with the circuit connection, kindly please do correct me.
If you are trying to communicate with the ADAU1701, why are you toggling the w5100 CS line? That is D10 (ETHCS). Which Arduino pin is the ADAU1701 CS line? Is that D9? If so, you should be using that instead of D10 (ETHCS).
It’s true that I am trying to make Arduino Ethernet (Master) to communicate with the ADAU1701 (slave). What I understood, I am not toggling the w5100 CS line, since Arduino Ethernet pin for ADAU1701 CS line is connect to ETHCS or D10 (pin 14 at ATMEGA328) . The connectivity of D10 (ETHCS of Arduino Ethernet board) and pin 14 (SS) of ATMEGA328 is verified by using multimeter. Meanwhile, D9 of Arduino Ethernet Board is for Led (tested and verified by blinking program). If somehow my explanation a bit confusing, please pardon me and kindly do correct me.
I agree with SurferTim that the SPI wiring seems a bit strange.
Answered I guess.
I don't have one of these chips but your program does not make sense to me. What is on pin 9?
It is for LED at Ethernet Arduino Board.
Your pulsing the SS pin low three time to change from I2C to SPI and then going on to write commands but do you maybe need to add another HIGH/LOW toggle to finish the SPI setup?
should I modified this way?
//pull low clatch three times
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
//end pull low clatch three times
digitalWrite(ETHCS, LOW);
// write
//read
digitalWrite(ETHCS, HIGH);
You then going on to read address 0x081A (Data Capture 0) that is a 16 bit register but you look to be discarding the result with writing the next two bytes and then reading the next 3 bytes that are 'Data Capture 1' and half of 'DSP core control'.
DSP_CS_LOW;
spi_send_byte(0x01); // we need this, right ?
spi_send_byte(0x0B); // parameter value high
spi_send_byte(0x66); // palameter value low
/* read 3 bytes */
read_buf[0] = spi_send_byte(0xFF);
read_buf[1] = spi_send_byte(0xFF);
read_buf[2] = spi_send_byte(0xFF);
DSP_CS_HIGH;
A picture below was the register control of ADAU1701 screencaptured at sigmastudio software.
And I’ve read the CONTROL REGISTERS SETUP mentioned but still not understand it yet and dont know how to respond and take action.
Hence, could you guys please advise me on how do I proceed for the control register configuration in the Arduino script code or likewise to solve on other problems too? Thanks.
Your pulsing the SS pin low three time to change from I2C to SPI and then going on to write commands but do you maybe need to add another HIGH/LOW toggle to finish the SPI setup?
should I modified this way?
//pull low clatch three times
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
//end pull low clatch three times
From the links to sample code you supplied yes you need the extra ETHCS = HIGH to finish the change from I2C to SPI.
And I’ve read the **CONTROL REGISTERS SETUP** mentioned but still not understand it yet and dont know how to respond and take action.
Hence, could you guys please advise me on how do I proceed for the control register configuration in the Arduino script code or likewise to solve on other problems too? Thanks.
I would start by breaking the code down into blocks (functions) that will aid in the readability of your program flow and reduce risk of errors. Below is a sample of what I mean, it is obviously untested but should work (famous last words) and give you an idea of what I'm referring to.
The DSP_Init code sets the SPI mode and sends the minimum config required as per data sheet. There are 16 bit (2 byte) read/write functions that should be expanded to do between 1 & 5 bytes. Maybe the way to go would be to use a 5 byte buffer to send/receive data where you load the buffer with data and call a function to send the required number of bytes or read them back. (So many different ways of doing this though).
#include <SPI.h>
int ETHCS = 10;
//byte DSP_Buffer[5];
void setup() {
SPI.begin();
DSP_Init();
pinMode(9, OUTPUT);
digitalWrite(9,LOW);
Serial.begin(57600);
Serial.println(DSP_Read16(0x081C),HEX);
}
void loop(){
}
void DSP_Init(){
//SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
pinMode(ETHCS, OUTPUT);
//pull low clatch three times to put DSP into SPI mode
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
delay(50);
DSP_Write16(0x081C,0x1C); // DSP Core Control (ADM, DAM, CR)
DSP_Write16(0x0827,0x01); // DAC Setup (DS0)
}
unsigned int DSP_Read16(unsigned int address){
byte result8;
unsigned int result16;
digitalWrite(ETHCS, LOW);
SPI.transfer(0x01); // chip address and read bit
SPI.transfer((byte) address >> 8); // MSB address
SPI.transfer((byte) address); // LSB address
result16 = SPI.transfer(0x00); // store read result in data0
result8 = SPI.transfer(0x00); // store read result in data1
result16 = (result16 << 8) | result8;
digitalWrite(ETHCS, HIGH);
return result16;
}
void DSP_Write16(unsigned int address, unsigned int data){
digitalWrite(ETHCS, LOW);
SPI.transfer(0x00); // chip address and write bit
SPI.transfer((byte) address >> 8); // MSB address
SPI.transfer((byte) address); // LSB address
SPI.transfer((byte) data >> 8); // MSB data
SPI.transfer((byte) data); // LSB data
digitalWrite(ETHCS, HIGH);
}
//pull low clatch three times
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
//end pull low clatch three times
If you are using D10 for anything, don't. It is the w5100 CS.
edit: This is from the Arduino Ethernet page:
NB: Pins 10, 11, 12 and 13 are reserved for interfacing with the Ethernet module and should not be used otherwise. This reduces the number of available pins to 9, with 4 available as PWM outputs.
SurferTim:
This pulls the w5100 CS low three times also.
//pull low clatch three times
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
digitalWrite(ETHCS, LOW);
digitalWrite(ETHCS, HIGH);
//end pull low clatch three times
Not sure who this is meant for Tim but in case it was me the OP's original code pulled SS low 3 times but on the third low went straight into SPI transfer hence my suggestion to do the final high to finish with.
If you are not aware the ETHCS pin is D10, and it is the w5100 slave select, then it is aimed at both of you. I edited my previous post to add the quote and reference.
Point taken, I had not noticed the Arduino was an Ethernet model.
kaeroul you will need to use either a different Arduino or a different pin for CS as the current choice (pin 10) means you will be reading/writing to the Ethernet module also and this will cause problems.
From your guys suggestion, I decided to pull out the wiznet chip, but, Somehow my supervisor ask me to change to an i2c communication mode since many messy modification we need to work on for the SPI comm using Arduino Ethernet and EVAL-ADAU1701MINIZ . The current major problem is actually, MOSI signal voltage (from arduino) after go through diode 1N5822, seems suppressed by an EVAL-ADAU1701MINIZ circuit, once both SPI devices connected and powered. I can confirmed that suppression, by measuring using an oscilloscope and it gives me no signal but noise on ADAU1701 MOSI(CDATA) line.
I am going to zero again to start find out the appropriate circuit for connecting those I2C devices since both are operating in different voltage (3.3V and 5V).
Anyway, Thanks SurferTim and Riva for your help and hardworks. Insyaallah, Ill get back here once the project comes to SPI again...
I would look at the design of bi-directional level converters like the Sparkfun one.
If you don't need Ethernet then maybe one of the 3.3V Arduino's like this will do the job.
I’m now back to solve this SPI communication again. My I2C communication doing just a bit fine but got 'pop' and 'click' noise problem at speaker during interaction between Arduino and EVALADAU1701 board.
To continue start with previous discussion, Below is my schematic:
I’ve did the bi-directional level converter and tried riva’s code by adding:
void loop(){
DSP_Write16(0x081A,0x00FE); //parameter data 0x00FE at address 0x081A capture window
Serial.println(DSP_Read16(0x081A),HEX);
delay(100);
}
But still don’t get the correct value. It just give me at serial window: