Hi guys, I have a problem by reading the GCLK registry in my Arduino MKR WiFi 1010.
I've tried to follow the (not so detailed) description from the Atmel-42181-SAM-D21 Datasheet. It says:
14.6.4.1 Indirect Access
...
To read a register, the user must write the ID of the channel, i, in the corresponding register. The value of the register for the corresponding ID is available in the user interface by a read access.
For example, the sequence to read the GENCTRL register of generic clock generator i is:
- Do an 8-bit write of the i value to GENCTRL.ID
- Read GENCTRL
This is how my code looks like:
setup() {
int32_t reg;
while (GCLK->STATUS.bit.SYNCBUSY); // just to be sure
Serial.print(F("GCLK->GENCTRL[0]: "));
// variant 1, freezes the processor
GCLK->GENCTRL.reg = GCLK_GENCTRL_ID(0);
while (GCLK->STATUS.bit.SYNCBUSY); // optionally tried to wait for syncing before read, same result
reg = GCLK->GENCTRL.reg;
// variant 2, freezes the processor
GCLK->GENCTRL.bit.ID = 0;
while (GCLK->STATUS.bit.SYNCBUSY); // optionally tried to wait for syncing before read, same result
reg = GCLK->GENCTRL.reg;
Serial.println(reg, BIN);
}
Where am I wrong?
Thanks in advance
Zsolt