Hi guys
I’m trying to interface my Arduino Mega 2560 with a TDA7439 (audio processor , with tone , gain control) {http://pdf.datasheetcatalog.com/datasheet/stmicroelectronics/4291.pdf}
This IC comunicates by serial interface to be programmed , but has not standards pins (MISO, MOSI,SS, CLK) for serial comunication but just SCLK and SDA lines. So, to “start” a comunication Arduino must send a falling edge of SDA line when CLK is HIGH and then send 3 byte with a clock pulse between them in mode 0 0 (polarity and phase). to “stop” the comunication arduino send a rising edge when CLK is HIGH.
So that is the problem: I need to program Arduino to send the right string in SDA with the right time respect the CLK signal, so
I’m using the SPI library and with transfer() function everything seems easy , but I don’t know exactly what this function do.
does It make CLK oscillating only when transfer() is called?
Is strictly necessary to call SPI.begin() to start a serial comunication with other devices?
I attach my sketch for a look:
I’ve declared a void function (byte WORD1, byte WORD2, byte WORD3) to send the 3 words via serial in the right way.
the void loop() is not completed yet , What I really need to know is if this function correctly send the data bytes .
#include <SPI.h>
int SMOSI=51;
int SCLK=52;
int Ss=53;
byte address=10001000;
void setup() {
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
pinMode(SMOSI,OUTPUT);
pinMode(SCLK,OUTPUT);
pinMode(Ss,OUTPUT);
}
void loop() {
byte InputGain=map(analogRead(A1),0,1023,0,16);
byte Volume=map(analogRead(A2),0,1023,0,40);
byte BassGain=analogRead(A3);
int MidGain=analogRead(A4);
int Treble=analogRead(A5);
int SpeakerGain=map(analogRead(A6),0,1023,0,56);
}
//funzione di trasmissione seriale lungo le linee MOSI e CLK (piedini 51, 52);
void serialToTDA(byte WORD1, byte WORD2 , byte WORD3)
{// start
digitalWrite(SMOSI,HIGH);
digitalWrite(SCLK,HIGH);
delayMicroseconds(4);
digitalWrite(SMOSI,LOW);
//transfer address of TDA3974
SPI.transfer(WORD1);
delayMicroseconds(4);
SPI.transfer(WORD2);
delayMicroseconds(4);
SPI.transfer(WORD3);
delayMicroseconds(4);
digitalWrite(SMOSI,LOW);
digitalWrite(SCLK,HIGH);
delayMicroseconds(2);
digitalWrite(SMOSI,HIGH);
}