0
\$\begingroup\$

enter image description hereI want a 24 bit resolution AD conversion, so I am using an audio ADC CS5385. I am not in any way working with audio signal, but I just want to get the digital values from the ADC via the I2S interface.

My ADC is the master and the PIC32 is the slave (as directed by ADC datasheet).

so after the ADC does it conversion i just want to take in the I2S signals from the SDI and send it out via the SDO. thank you for your time

// asm volatile("ei"); // Enable all interrupts - this funnction stops my refclock out

Thanks

Mclck - 8MHZ from Pbclck

I am using sysclck at 8 mhz with internal RC and pbclck divider of 1 and sending PBCLCK out as refclckout.

here is my code

define SYS_FREQ 8000000
include <xc.h>
include <sys/attribs.h>
include <plib.h>

int main(void);
void SYSTEM_RegUnlock(void);
void SYSTEM_RegLock(void);
void OSCILLATOR_Initialize(void);



int main(void) {
   SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
   DDPCONbits.JTAGEN = 0;



   ANSELA = 0x0000; // all ports digital
   ANSELB = 0x0000; // all ports digital

   TRISBbits.TRISB3 = 0; // make RA1 pin LED - 7

   // PIN INTIALIZATION
   PORTBbits.RB9 = 0; // make RB9 pin MDIV
   PORTBbits.RB7 = 0; // make RB7 pin ~HPF
   PORTBbits.RB4 = 0; // make RB4 pin I2S/~LJ
   PORTBbits.RB5 = 0; // make RB5 pin M1
   PORTAbits.RA4 = 0; // make RA4 pin M0
   PORTBbits.RB0 = 1; // make RB0 pin ~RST
   PORTBbits.RB1 = 1; // make RB1 pin M/~S

   //PORTBbits.TRISA0 = 0; // make RB2 pin output- 6
   PORTBbits.RB3 = 1; // make RA1 pin LED - 7

   // SPI PINS
   TRISBbits.TRISB14 = 1; // RPB14 = Input -25 SCK - SCLK
   TRISBbits.TRISB15 = 1; // RPB15 = Input -26 ~SS-LRCLK
   TRISBbits.TRISB8 = 1; // RPB8 = SDI - 17
   TRISBbits.TRISB2 = 0; // make RB2 pin output(SD0)- 6
   TRISBbits.TRISB13 = 0; // RPB13 = REFERENCE output - 24

   SYSTEM_RegUnlock(); // unlock PPS
   CFGCONbits.IOLOCK = 0;
   //CFGCONbits.PMDLOCK=0;

   RPB13Rbits.RPB13R = 0x0007; //RB13->INTERNAL OSCILLATOR:REFCLKO;
   SS1Rbits.SS1R = 0x0003; //RB15->SPI1:SS1;
   RPB2Rbits.RPB2R = 0x0003; //RB2->SPI1:SDO1; - 6
   SDI1Rbits.SDI1R = 0x0004; //RB8->SPI1:SDI1;

   CFGCONbits.IOLOCK = 1; // lock PPS

   //CFGCONbits.PMDLOCK = 1;

   SYSTEM_RegLock(); 

   //__builtin_disable_interrupts();
   //asm volatile("di"); // Disable all interrupts

   IEC1 = 0; // disable all interrupts
   SPI1CON = 0; // Stops and resets the SPI1.
   SPI1CON2 = 0; // Reset audio settings
   // REFOCON = 0x0; // Reset reference oscillator

   rdata = SPI1BUF; // clear the receive buffer 
   IFS1 = 0x00;// clear any existing event 
   IPC7 = 0x00;// clear the priority 
   IPC7bits.SPI1IP = 3; // Set IPL = 3, 
   IPC7bits.SPI1IS = 1; // Subpriority 
   IEC1bits.SPI1RXIE = 1;
   IEC1bits.SPI1TXIE = 1;
   IEC1bits.SPI1EIE = 1;
   SPI1STATCLR = 0x40; // clear the overflow
   SPI1CON2 = 0x000000c1; // Left-Justified Mode, AUDEN = 1, AUDMON = 0
   SPI1CON = 0xc1028cc0; // Slave mode, SPI ON, CKP = 1 

   // 24-bit audio data, 32 bits per frame 

   OSCILLATOR_Initialize();

   // Enable the multi vector
   INTCONbits.MVEC = 1;

   // asm volatile("ei"); // Enable all interrupts

   while (1) { 
      while (!SPI1STATbits.SPIRBF); // wait for receive complete
      PORTBbits.RB3 = 0; // light LED
      channel = SPI1BUF; // read from buffer
      while (!SPI1STATbits.SPIRBF);
   }
}

void SYSTEM_RegUnlock (void)
{
   SYSKEY = 0x12345678;
   SYSKEY = 0xAA996655;
   SYSKEY = 0x556699AA;
}

void SYSTEM_RegLock (void)
{
   SYSKEY = 0x00000000; 
}

void OSCILLATOR_Initialize (void)
{
   SYSTEM_RegUnlock(); 
   OSCCON = 0x38000;
   SYSTEM_RegLock();
   OSCTUN = 0x0;
   // DIVSWEN disabled; RSLP disabled; ACTIVE Active; ROSEL SYSCLK;
   // OE N Driven out on REFCLKO pin; SIDL disabled; RODIV 0; ON disabled; 
   REFOCON = 0x00009101;
}
\$\endgroup\$
  • \$\begingroup\$ I think we need to see schematics how the ADC is connected to PIC. The protocol is typically I2S but some varians can be SPI compatible. What is the master clock to the DAC as the DAC is the master? \$\endgroup\$ – Justme Apr 2 at 4:51
  • 4
    \$\begingroup\$ Possible duplicate of Interfacing audio ADC WITH PIC32MX250128B \$\endgroup\$ – jsotola Apr 3 at 1:32
  • \$\begingroup\$ why are you asking this again? ...... if you have any additional information, please add it to your first question \$\endgroup\$ – jsotola Apr 3 at 1:32
  • \$\begingroup\$ I added new info to this new question, the mclk is 8MHZ thanks using refclcko from MCU i used PBCLCK \$\endgroup\$ – Charlieduru Apr 3 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.