Thanks both for the replies. Thanks Mark for the code snippet, but after some time spent to make PE work with MQX and a
lot of problems I decided to stop using PE. It is a nice fancy tool but not for complicated projects. I am trying now BSP, although
I have many problems and I suppose the main cause of them is that all these upper layers are black boxes for the user.
I tried to open and close the analog channel using every time a different structure but nothing.
Here is a simple 1 channel project that again cannot initialize f_ch1 which always return 0.
#include <mqx.h>
#include <bsp.h>
#define MY_ADC "adc1:" /* must be #1 as the inputs are wired to ADC 1 */
#define MY_TRIGGER ADC_PDB_TRIGGER
/* Task IDs */
#define ADC_TASK 6
/* Function prototypes */
extern void main_task(uint_32);
void adc_task(uint_32);
const TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */
{ADC_TASK, adc_task, 1000, 7, "Adc", MQX_AUTO_START_TASK, 0, 0 },
{0}
};
/* ADC device init struct */
const ADC_INIT_STRUCT adc_init = {
ADC_RESOLUTION_DEFAULT, /* resolution */
};
/* Logical channel #1 init struct */
const ADC_INIT_CHANNEL_STRUCT adc_channel_param1 =
{
ADC1_SOURCE_AD12, /* physical ADC channel */
ADC_CHANNEL_MEASURE_LOOP | ADC_CHANNEL_START_NOW, /* runs continuously after IOCTL trigger */
10, /* number of samples in one run sequence */
0, /* time offset from trigger point in us */
10000, /* period in us (= 0.3 sec) */
0x10000, /* scale range of result (not used now) */
10, /* circular buffer size (sample count) */
MY_TRIGGER, /* logical trigger ID that starts this ADC channel */
};
void adc_task
(
uint_32 initial_data
)
{
ADC_RESULT_STRUCT data;
MQX_FILE_PTR f, f_ch1;
printf("\n\n-------------- Begin ADC example --------------\n\n");
printf("Opening ADC device ...");
f = fopen(MY_ADC, (const char*)&adc_init);
if(f != NULL)
{
printf("done\n");
}
else
{
printf("failed\n");
_task_block();
}
while(1){
f_ch1 = fopen(MY_ADC "gyrox", (const char*)&adc_channel_param1);
read(f_ch1, &data, sizeof(data));
printf("GYROX: %4d\n\r ", data.result);
fclose(f_ch1);
}
}
/* EOF */
THANKS