Part Number: MSP432P401R
Tool/software: TI-RTOS
Let me preface by saying that I am new to using the TI-RTOS, so the mistake might be something obvious.
The issue itself, is that TSK_read_accelerometer() is only running once then it terminates.
I have edited MSP_EXP432P401R.c, MSP_EXP432P401R.h, and Board.h to add support for ADC Channels 11, 13, and 14 to be able to use the accelerometer on the Booster Pack.
This is the task itself. SEMHDL_update_accel is posted by a clock module. That code will also be posted below.
Void TSK_read_accelerometer()
{
while(1) {
// wait for resource to be available
Semaphore_pend(SEMHDL_update_accel, BIOS_WAIT_FOREVER);
// disable all other interrupt sources; Hwi_disable() also disables tasks and Swis
// UInt key = Hwi_disable();
// update accel prev
accel_prev = accel_current;
// update accel_current
accel_current.z = ADC_read_z_axis();
accel_current.y = ADC_read_y_axis();
accel_current.x = ADC_read_x_axis();
// update accel max values
if (accel_current.z > accel_max.z)
accel_max.z = accel_current.z;
if (accel_current.y > accel_max.y)
accel_max.y = accel_current.y;
if (accel_current.x > accel_max.x)
accel_max.x = accel_current.x;
// Check for fall detection
if ( (accel_current.z > accel_prev.z - 3000) ||
(accel_current.z < accel_prev.x + 3000) ||
(accel_current.z > 15000)) {
Clock_start(CLK_HDL_enable_buzzer);
}
System_printf("X: %d\t", accel_current.x);
System_printf("Y: %d\t", accel_current.y);
System_printf("Z: %d\n", accel_current.z);
System_flush();
}
// re-enable Hwi's, Swi's, and tasks
// Hwi_restore(key);
}
Here is the clock module code. It is periodic.
Void CLK_TSK_read_accelerometer()
{
Semaphore_post(SEMHDL_update_accel);
}
Here is a sample that reads a single ADC channel. It is very similar to the driver example.
uint16_t ADC_read_z_axis()
{
ADC_Handle adc;
ADC_Params params;
uint16_t adc_val;
int_fast16_t res;
ADC_Params_init(¶ms);
adc = ADC_open(Board_ADC11, ¶ms);
/*
if (adc == NULL) {
System_abort("Error initializing ADC channel z\n");
}
else {
System_printf("ADC channel z initialized\n");
}
*/
res = ADC_convert(adc, &adc_val);
if (res == ADC_STATUS_ERROR) {
adc_val = 0;
}
ADC_close(adc);
return adc_val;
}
Here is the console output. It prints the ADC values only a single time.
System provider is set to SysMin. Halt the target to view any SysMin contents in ROV.
X: 10986 Y: 10947 Z: 14886
FSR = 0x0000
HFSR = 0x40000000
DFSR = 0x00000001
MMAR = 0xe000ed34
BFAR = 0xe000ed38
AFSR = 0x00000000
Terminating execution...
Update: I found out that the issue is Clock_start(CLK_HDL_enable_buzzer); being called within my task. Why would this be causing these issues?
Update 2: I reread the user guide. The clock module runs as a Swi, and according to the documentation only a Hwi or Swi can post another Swi. I'm essentially posting a Swi from a Task.
Here's my entire project code: Project5_Peters.zip

