HW = Arduino Due and Wolfson WM8737 Audio ADC
Arduinoe SW version = 1.5.5
Computer: Mac OSX 10.9.1
Problem: The Wolfson ADC requires a 12MHz clock. The internal MAINCLK of the SAM3X is the buffered crystal frequency of 12MHz. The SAM3X Programmable Clock Output Controller PCOC allows MAINCLK to be routed to one of the PCKx (x = 0,1,2) pins.
On the Due board, some pin options for PCKx are:
PCK0 = PA1 mapped to CANRX , pin 68
PCK1 = PA24 mapped to analog in A3, pin 55
PCK2 = PA28 mapped to NPCSO (SPI), pin 77
32 bit Registers that control PCOC are:
PMC_SCER (PMC System Clock Enable Register) address is 0x400E0600, write only,
PMC_SCDR (PMC System Clock Disable Register) address is 0x400E0604, write only,
PMC_SCSR (PMC System Clock Status Register) address is 0x400E0608, read only. PMC_PCKx (PMC Programmable Clock Register) address is 0x400E0640, read/write.
PMC_WPMR (PCM Write Protect Mode Register) address is 0x400E06E4, read-write.
(PMC_SCER and PMC_SCDR and PMC_PCKx can only be written to if the WPEN bit is in the PMC Write Protect Mode Register)
My experimental code is below. There are several embedded questions. The code compiles, yet there is no clock signal on the PCK0 pin 68. The Serial.print result for the status register is 100001 which should have been 100000000 for PCK0 active.
Both PMC->register name and REG_registername methods resulted in the same lack of PCK0 activation.
Both REG_PMC_SCER |= 0x100; and REG_PMC_SCER = 0x100; resulted in a status read back of 100001 (bit 8 low).
Thanks
void setup()
{
Serial.begin(9600);
// Define PA1 (PCK0) as an digital output pin
// DDRA = (DDRA | 0x1); // ERROR; 'DDRA' was not declared in this scope
// Question: DDRA works with ATmega2560, SAM3X is different?
pinMode (68, OUTPUT); // pin 68 is PA0 - needed for PCK0
// Question: does this override the default Arduino CANRX mapping for this pin?
}
void loop()
{
// Enable writing to PCOC registers
// PMC->PMC_WPMR = 0x504D4301; // bit 0 high sets the WPEN value
REG_PMC_WPMR = 0x504D4301; // either register assignment compiles
// Select the MAINCLK and set the divider to /1;
//REG_PMC_PCK0 |= 0x1; // ERROR: " 'REG_PMC_PCK0' was not declared in this scope". Is this a invalid command?
// PMC_PCK0 is defined as a valid register name in Table 29-3.
PMC->PMC_PCK[0] = 0x1; // From forum "ARDUINO DUE PMC REGISTERS" June 6 2013
// CSS assigned to bits 0 - 2, CSS = 1 selects the Main (crystal) Clock.
// PRES assigned to bits 4 – 6, PRES = 0 is associated with “divide by 1” option.
// Route internal clock to PCK0
// PMC->PMC_SCER |= 0x100; // bit 8 high enables PCK0 (B100000000)
REG_PMC_SCER |= 0x100;
// Disconnect PCK0 from internal clocks
// PMC_SCDR =| 0x100) ; // bit 8 high disables PCK0
// Disable writing to PCOC registers
// PMC->PMC_WPMR = 0x504D4300; // bit 0 low resets the WPEN value
REG_PMC_WPMR = 0x504D4300;
// To verify the status of PCK0, read PMC_SCSR and verify bit 8 is high
// Serial.println (“the 8th bit of the PMC System Clock Status Register is PCK0 status“);
// The line above creates many errors in Beta 1.5
Serial.println (REG_PMC_SCSR, BIN);
while(1);
}