SSC I²S with arduino DUE

hello,

i want to make music with an arduino due and a DAC 24 bits.

first i want to configure the Synchronous Serial Controller SSC. Before to look for TD and TF i try to get a signal out from the TK of the due (the master clock for the DAC).

//Synchronous Serial Controller
  
  //3 pins in peripheral B of PIOA
  //TK : MCLK   pin 23 ( PIOA 14 )
  //TF : FS     pin 24 ( PIOA 15 )
  //TD : SDATA  pin A0 ( PIOA 16 )
  
  //PIO
  PMC->PMC_PCER0 = 1 << 11;// enable PIOA in PMC
  PIOA->PIO_WPMR = (0x50494F << 8) | 0b0 ;//disable write protection
  PIOA->PIO_PDR = 0b111 << 14;//give the control of the 3 pins to the SSC peripheral
  PIOA->PIO_ABSR = 0b111 << 14; //Assigns the I/O lines to the Peripheral B function (TD TK TF)
  
  
  
  PMC->PMC_PCER0 = 1 << 26;//enable SSC in PMC
  SSC->SSC_WPMR = 0x535343 | 0b0;//disable write protection
  SSC->SSC_TCMR = 0b00;//clock divider for SSC
  SSC->SSC_CMR = 0b1;//value of the clock divider

but with this code i get nothing from TK pin.

thanks for help

Setting TK clock is rather simple as per datasheet. Note that you don't have to power PIOA, it's done by the peripheral, disabling Write protection is useless, and a good rule is to avoid magic numbers since everything is in the header files.

In the example below, I check that TK outputs a signal at the correct pace by blinking an LED:

/**********************************************************/
/*     Jumper between pin 23 (PA14 = TK) and pin 25       */
/**********************************************************/

void setup() {

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(25, INPUT);
  PMC->PMC_PCER0 |= PMC_PCER0_PID26; // SSC Power ON

  PIOA->PIO_PDR = PIO_PDR_P14 |      // The pins are no more driven by the GPIO
                  PIO_PDR_P15 |
                  PIO_PDR_P16;
  PIOA->PIO_ABSR |= PIO_PA14B_TK |   // Set the pins to the SSC peripheral
                    PIO_PA15B_TF |
                    PIO_PA16B_TD;

  SSC->SSC_CMR |= SSC_CMR_DIV(4095);  // Select the clock divider you want
  SSC->SSC_TCMR = SSC_TCMR_CKS_TK | SSC_TCMR_CKO_CONTINUOUS;

  attachInterrupt(25, _ISR, RISING);
}

void loop() {

}
void _ISR()
{
  static uint32_t Count;
  if (Count++ > 10256)
  {
    PIOB->PIO_ODSR ^= PIO_ODSR_P27;
    Count = 0;
  }
}

hello ard_newbie,

thanks for the answer. I have forgotten the CKO field in TCMR (continuous), now it works and effetively Write protection is disabled by default.

I have an other issue. If i want the CPU to execute other instructions in same time, the noise (produced by the execution of the instructions) is completely masking the TK clock.

electric potential on a pin with void loop() empty (and without SSC configured, just to see the noise):

electric potential on a pin with random instructions in void loop() (and without SSC configured, just to see the noise):


that noise is completely masking the clock so it seems that due can't produce a good master clock to drive a device with SSC

the (weak) TK clock with no noise (no other instructions):

It's a total nonsense, I'm sure you are missing something. :o

If that was the case, the LED wouldn't blink with a constant 1 Hz frequency in the sketch provided in reply #1.

Usually, pins are connected to pull-down or pull-up resistors to avoid EMI.

Post a schematic of your wirings.

hello!

i'm so stupid! i was using an oscilloscope to check the TK signal made by your sketch (not i diode) and i plugged the probe in pin 24 instead of pin 23...... so i was looking at the noise that it produce and not at the real signal

thanks again!