Interface audio chip M61540FP with clock and data

I want to command the M61540FP chip with arduino. The M61540FP chip uses the TWI protocol, but has no starting address. The TWI protocol is compatible with I2C, but the main problem is that both need the starting address. I looked for examples of libraries and codes, but none of them look like what I have. Is there any way to trick the code into working without the address?
Thank you in advance.

If you study the M61540FP data sheet, you will see that the device expects 24 bits to be sent in a single transaction, which is easy to accomplish ("bit bang") using a single
for loop controlling two port pins.

No, the chip uses neither TWI nor I2C. As @jremington pointed aut, it is a simple serial shift protocol that can be easily implemented.

Thank you for the answers.
Should this code work? I don't have much knowledge in programming, now I'm learning it. The code is made after an example of communication on SPI.

#include "SPI.h"

const int CS_PIN = 11;
const int M61540FP_SCLK_PIN = 13;
const int M61540FP_SDI_PIN = 12;

void setup() {
pinMode(CS_PIN,OUTPUT);
pinMode(M61540FP_SCLK_PIN,OUTPUT);
pinMode(M61540FP_SDI_PIN,OUTPUT);
digitalWrite(CS_PIN,HIGH);
digitalWrite(M61540FP_SCLK_PIN,HIGH);
digitalWrite(M61540FP_SDI_PIN,HIGH);
Serial.begin(9600);
}

void M61540FP_set(byte value1, byte value2, byte value3)
{
byte shifted_val1 = (value1 << 1);
byte shifted_val2 = (value2 << 1);
byte shifted_val3 = (value3 << 1);
DATA_write(shifted_val1);
DATA_write(shifted_val2);
DATA_write(shifted_val3);
}

static inline void DATA_write(byte out_data_byte)
{
byte i;

for (i=0; i < 8; i++) { // loop thru each of the 8-bits in the byte

digitalWrite(M61540FP_SCLK_PIN, LOW); // strobe clock

if (0x80 & out_data_byte) // send the bit (we look at the high order bit and 'print' that to the remtoe device)
digitalWrite(M61540FP_SDI_PIN, HIGH); // MSB is set
else
digitalWrite(M61540FP_SDI_PIN, LOW);

digitalWrite(M61540FP_SCLK_PIN, HIGH); // unstrobe the clock
out_data_byte <<= 1; // left-shift the byte by 1 bit
}
}

Or do you have another code example to follow?

Lots of problems with that code. There is no "CS" on the volume control chip.

I would approach the problem using something like this (untested):

int datapin=2;
int clockpin=3;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
Serial.println("M61540FP test");

pinMode(datapin, OUTPUT);
digitalWrite(datapin,0);
pinMode(clockpin, OUTPUT);
digitalWrite(clockpin, 0);

byte low = 0; //set bits as needed
byte med = 1;
byte high = 2;

// pack low, med and high bytes into a 32 bit long

unsigned long data = (((unsigned long)high)<<16) | (((unsigned long)med) << 8) | (unsigned long) low;
Serial.println (data, HEX);  //check formatting

// transmit the three bytes

for (byte i=0; i<24; i++)
digitalWrite(datapin,(data&1));  //set data pin, lowest bit first
delayMicroseconds(2);  //minimum 1.6 microseconds
digitalWrite(clockpin,1);  //set clock pin high
delayMicroseconds(2);
digitalWrite(datapin,0);  //ready for next bit
delayMicroseconds(2);
digitalWrite(clockpin,0);  //reset clock line
delayMicroseconds(2);
data >>= 1;  //shift all bits down
}

Note: evidently 4 slots have to be filled, each with 24 bits of data.

Isn't the latch bit at the end of transmission missing?

    for (byte i = 0; i < 24; i++) {
        digitalWrite(datapin, (data & 1)); //set data pin, lowest bit first
        delayMicroseconds(2);  //minimum 1.6 microseconds
        digitalWrite(clockpin, 1); //set clock pin high
        delayMicroseconds(2);
        digitalWrite(datapin, (i==23 ? 1:0) ); //ready for next bit - or latch at end
        delayMicroseconds(2);
        digitalWrite(clockpin, 0); //reset clock line
        delayMicroseconds(2);
        data >>= 1;  //shift all bits down
    }
1 Like

Good catch. I have no way of testing the code.

Neither do I. @george9801 must do that himself :wink:

@george9801 Could you scroll up and edit the title. Please remove the term "TWI". What about: "Interface audio chip M61540FP with clock and data".

I changed the title.
First I will simulate the code in Proteus (ISIS), then I will do the physical assembly. So all I have to do is assign values to the low, med and high bytes?

There is an other option to simulate the code.
Wokwi has a Logic Analyzer. You need to install the PulseView logic analyzer to open the VCD files, but once everything is working, it can be really useful.

You assign the low, med, and high byte. Then make a 'unsigned long' from those. Then shift the 24 bits. When talking about code, we prefer that you show us your sketch.

No, there is a lot more involved in getting this chip to work. Start by learning to understand the apparently independent control "slots" mentioned in the data sheet, in the material following the section titled "Data Control Specification".

I've studied the data sheet for a while, and don't understand it completely. My current understanding is that you send 3 bytes of data in four independent steps, each filling different slots of a 12 byte memory. The slots are indexed by the top two bits of the 24 bit data stream.

How are you planning to mount and test this chip? It needs quite a number of resistors and capacitors, as well as three power supplies!

The chip is already mounted in the circuit. All need is his command. The chip is soldered to a board recovered from an audio amplifier.