Hello all,
I am a new user of the Kinetis MCU's.
I am experimenting with the Freedom board.
I have created a simple program on the Freedom board which blinks the RGB leds. Initially, I created the project using "Device Initialization".
Using the Hardware Prespective, I setup the LED ports and the System Timer (SysTick). I then accidentally, clicked on the "DAC0" block in the IC outline, which immediatly generated the following code in the MCUInit module...
/* ### Init_DAC init code */
/* DAC0_C0: DACEN=0,DACRFS=0,DACTRGSEL=0,DACSWTRG=0,LPEN=0,DACBTIEN=0,DACBBIEN=0 */
DAC0_C0 &= ( uint8_t)~(uint8_t)0xFBU;
/* DAC0_SR: DACBFRPTF=0,DACBFRPBF=0 */
DAC0_SR &= (uint8_t)~(uint8_t)0xFBU;
/* DAC0_DAT0L: DATA0=0 */
DAC0_DAT0L = (uint8_t)0x00U;
/* DAC0_DAT0H: DATA1=0 */
DAC0_DAT0H = (uint8_t)0x00U;
/* DAC0_C1: DMAEN=0,DACBFMD=0,DACBFEN=0 */
DAC0_C1 &= (uint8_t)~(uint8_t)0xE5U;
/* DAC0_C0: DACEN=0,DACRFS=0,DACTRGSEL=0,DACSWTRG=0,LPEN=0,DACBTIEN=0,DACBBIEN=0 */
DAC0_C0 &= (uint8_t)~(uint8_t)0xFBU;
/* ### Init_DAC init code */
/* CMP0_DACCR: DACEN=0,VRSEL=0,VOSEL=0 */
CMP0_DACCR = (uint8_t)0x00U;
The component inspector for the DAC shows that; pins, interrupts, and device initialization are disabled, however, code is ALWAYS generated when the "Generate Code" button is clicked in the Hardware Prespective.
This in itself would not be a problem, except that apparently, a Hard Fault is generated when the first line of the DAC initialization code is executed.
DAC0_C0 &= ( uint8_t)~(uint8_t)0xFBU;
According to the data sheet, this statement should do nothing more than leave the register as it was before it was called.
Commenting out the initialization code corrects the problem, and allows my test program to run fine.
The question is: what is this statement doing to cause a Hard Fault.
I have attached the entire MCUInit module which is causing the fault
Thanks in advance,
Mike
Original Attachment has been moved to: MCUinit.c.zip
已解决! 转到解答。
Thank you Jim for pointing me in the right direction.
Sure enough, when you mouse hover over the DAC clock gate settings in the Component Inspector you get a warning message.
See attached.
KLQRUG mentions the need to enable clock gate for; DMA, ADC, UART, TPM, but I did not see it for DAC. I should've assumed.
Thanks again.
Mike