I'm trying to use the Captivate functionality of the MSP430FR2676 to read one electrode. When I do this in a simple prototyping project, I can make repeated calls to 'CAPT_updateSensorRawCount
' and the function returns as expected continually. When I integrate that same code into my production project, the function call may return correctly for one or more invocations, but eventually it will not return. Interrupts continue to assert and be serviced elsewhere.
My setup code is as follows:
// Power on the captivate peripheral MAP_CAPT_powerOn(); // Reset the captivate peripheral MAP_CAPT_reset(); // Initialize the captivate peripheral MAP_CAPT_init(); // Set input impedance to maximum CAPT_selectInputImpedanceBiasCurrent(eZeroIbias); // Set voltage source to internal voltage CAPT_selectElectrodeChargeVoltageSource(eVRegSupply); // Initialize the sensor IO CAPT_initSensorIO(&_sensor); // Enable the peripheral (?) sensor CAPT_enableSensorIO(&_sensor); // Initialize the sensor CAPT_initSensor(&_sensor); CAPT_enableISR(CAPT_END_OF_CONVERSION_INTERRUPT); _last_event_ms = tick_get_uptime_ms(); _last_capsense_counts = 0; DEBUG_HIGH(); CAPT_updateSensorRawCount(&_sensor, eStandard, eNoOversampling, LPM0_bits); DEBUG_LOW();
And my periodic code is as follows:
void captivate_interface_periodic(void) { uint16_t current_uptime_ms; if (g_bEndOfConversionFlag) { g_bEndOfConversionFlag = false; DEBUG_HIGH(); // *** THIS CALL WILL NOT RETURN CAPT_updateSensorRawCount(&_sensor, eStandard, eNoOversampling, LPM0_bits); DEBUG_LOW(); _last_capsense_counts = _element.ui16CompositeRawCount; _last_event_ms = _tick_get_uptime_ms(); } else { current_uptime_ms = _tick_get_uptime_ms(); if (CAPSENSE_TIMEOUT_MS < (current_uptime_ms - _last_event_ms)) { self_testing_failsafe(EVENT_CODE_CAPSENSE_TIMEOUT); } } }
From what I can tell by looking at the disassembly during debugging, my call in the initialization code to CAPT_enableISR(CAPT_END_OF_CONVERSION_INTERRUPT)
sets a bit at a symbol named 'CAPTIVATE_CAPIE', which is at address 0x0B20. When the call to CAPT_updateSensorRawCount(...)
does not return, the bit at the 'CAPTIVATE_CAPIE' address is still set, and global interrupts are still enabled. Assuming that CAPT_updateSensorRawCount(...)
requires interrupts in order to complete and return, it appears that the interrupts I can control are still enabled.
The application production project is more complex and enables and disables interrupts during critical sections. Because the Captivate library is either in a static library or embedded in ROM, I'm not able to find the source of the issue. However, if I attach a debugger and place a breakpoint at the CAPT_updateSensorRawCount(...)
call, and then Resume each time, it appears that the function returns more reliably. That seems to indicate that it is an race condition of some sort, possibly due to interrupts.
If there are any suggestions for finding the cause of this problem, please let me know.
Thanks for any help!