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() {

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

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
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.println("M61540FP test");

pinMode(datapin, OUTPUT);
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
digitalWrite(datapin,0);  //ready for next bit
digitalWrite(clockpin,0);  //reset clock line
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
        digitalWrite(datapin, (i==23 ? 1:0) ); //ready for next bit - or latch at end
        digitalWrite(clockpin, 0); //reset clock line
        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.

Hello. I wrote this code in arduino, but it doesn't work. On the output of the sound processor I only have a few beeps when I adjust the volume or the inputs. No sound. The M61540FP is part of an Onkyo TX 8050 amplifier.
On the arduino outputs (data and clock pins) I made a resistive divider with a resistance of 1k series and one of 2.2k at ground. What's wrong with my code?
Simulare_1_Onkyo_TX_8050.ino (27.2 KB)

I will simulate the code in Wokwi and come back tomorrow with the result.

I did look at your code when you posted it, but nothing caught my eye. Only that you mix 0 and 1 with LOW and HIGH, that is peanuts.

I did the simulation in Wokwi. It seems that the bits are read and forwarded back to the chip (from right to left). I tried to attach the simulation file with the .VCD extension, but it does not allow me to upload it to the forum. Instead, I attach four pictures with the pulses sent to the chip when starting (initializing) it.

It works! I reversed the bits (from left to right). Currently only the input setting and volume adjustment from -40dB to 0dB work. Thanks to everyone for their help. When I finish the code I will upload it here.

Simulare_1_Cod_Onkyo.ino (12.9 KB)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.