AnsweredAssumed Answered

KL65 ADC Implementation Hard Fault Error

Question asked by grant cazinha on Feb 15, 2017

I am using FreeRTOS am implementing several ADC channels using PE to generate code.  When I execute the code I hit a hard fault because it's trying to run the following line of code...

ADC1_CFG2 |= ADC_CFG2_MUXSEL_MASK;

 

The code tries to execute a write to a register that isn't initialized yet.

 

Has anyone else run into this issue and have you found a solution.  This is very frustrating.

 

Full code for the init_adc_pins function is as follows...

 

void init_adc_pins(uint32_t instance)
{
switch(instance) {
case ADC0_IDX: /* ADC0_IDX */
/* Affects PORTB_PCR0 register */
PORT_HAL_SetMuxMode(PORTB,0UL,kPortPinDisabled);
/* Affects PORTB_PCR1 register */
PORT_HAL_SetMuxMode(PORTB,1UL,kPortPinDisabled);
break;
case ADC1_IDX: /* ADC1_IDX */
/* Affects PORTB_PCR0 register */
PORT_HAL_SetMuxMode(PORTB,0UL,kPortPinDisabled);
/* Affects PORTB_PCR1 register */
PORT_HAL_SetMuxMode(PORTB,1UL,kPortPinDisabled);
/* Affects PORTB_PCR4 register */
PORT_HAL_SetMuxMode(PORTB,4UL,kPortPinDisabled);
/* Affects PORTB_PCR5 register */
PORT_HAL_SetMuxMode(PORTB,5UL,kPortPinDisabled);
/* Affects PORTB_PCR10 register */
PORT_HAL_SetMuxMode(PORTB,10UL,kPortPinDisabled);
/* Affects PORTB_PCR11 register */
PORT_HAL_SetMuxMode(PORTB,11UL,kPortPinDisabled);
/* ADC1_CFG2: MUXSEL=1 */
ADC1_CFG2 |= ADC_CFG2_MUXSEL_MASK;  <-----(This being my issue)
/* Affects PORTC_PCR8 register */
PORT_HAL_SetMuxMode(PORTC,8UL,kPortPinDisabled);
/* Affects PORTC_PCR9 register */
PORT_HAL_SetMuxMode(PORTC,9UL,kPortPinDisabled);
/* Affects PORTC_PCR10 register */
PORT_HAL_SetMuxMode(PORTC,10UL,kPortPinDisabled);
/* Affects PORTC_PCR11 register */
PORT_HAL_SetMuxMode(PORTC,11UL,kPortPinDisabled);
break;

Outcomes