µTasker Forum
µTasker Forum => NXPTM M522XX, KINETIS and i.MX RT => Topic started by: Chris on July 25, 2018, 03:24:10 AM
-
Hey Mark / Guys,
I am having an issue implementing ADC access in the Serial Bootloader....
I am using a slightly modified version of the uTaskerSerialBoot Application in KDS and I think something is going on that i might be simply overlooking.
I didn't see an easy way to access ADC channels so I attempted to initialize and read the hardware registers directly but I am running into resets when finishing the calibration routine or seemingly accessing any hardware addresses directly.
//----.h header-----
#define ADC0_CFG1 (*(volatile uint32_t *)0x4003B008)
#define ADC0_CFG2 (*(volatile uint32_t *)0x4003B00C)
#define ADC0_SC2 (*(volatile uint32_t *)0x4003B020)
#define ADC0_SC3 (*(volatile uint32_t *)0x4003B024)
#define ADC_SC3_CAL ((uint32_t)0x80)
//---- I call this function first without problems
//----.c code-----
void analog_init(void)
{
ADC0_CFG1 = (uint32_t)0x7B;
ADC0_CFG2 = (uint32_t)0x48;
ADC0_SC2 = (uint32_t)0;
ADC0_SC3 = (uint32_t)0x87;
}
//---- Then I call the following
void wait_cal(void)
{
int attemptscnt = 0;
while (ADC0_SC3 & ADC_SC3_CAL) {
attemptscnt += 1;
}
}
The code fails and the board resets as soon as i try to read ADC0_SC3..
thinking i might be waiting too long and inadvertently triggering a watchdog reset I changed
while (ADC0_SC3 & ADC_SC3_CAL) {
to
if (ADC0_SC3 & ADC_SC3_CAL) {
but the behavior continues...
It looks like the Kinetis_ADC stuff is all #ifdef out but I could be missing something that is causing a conflict
can you think of anything that might cause this or maybe have some things i could check for?
any help is greatly appreciated.
-
Hi Chris
If you add
#define SUPPORT_ADC
to config.h or app_hw_kinetis.h
the ADC interface will be enabled and you can use the same configuration as in ADC_Timers.h in the uTasker application.
In your code you may have missed enabling clocks to the ADC module before accessing it, otherwise it will result in a hard fault.
This can be done by adding
POWER_UP_ATOMIC(6, ADC0); before access
[or POWER_UP(6, SIM_SCGC6_ADC0); if your project version doesn't support the POWER_UP_ATOMIC() macro].
Good luck
Regards
Mark
-
Ah! enabling the clock did the trick thanks again, you rock!