Sorry, I meant to say the lwadc_vdac.c file.
Yeah, definitelly my suggestion will not work. The HC1 register does not expect bit-fields.
The patch from Rene should work.
I test Rene's changes updated to my version I working on (I'm not using the lwadc_vdac.c file from thread/317081), so I modified the read function in next way and it worked for me:
boolean _lwadc_read_raw(LWADC_STRUCT_PTR lwadc_ptr, LWADC_VALUE_PTR outSample)
{
ADC_MemMapPtr adc_ptr;
LWADC_VALUE sample;
uint_32 device, input;
_mqx_int ch_num;
if (NULL == lwadc_ptr){
return FALSE;
}
input = lwadc_ptr->input;
device = ADC_DEVICE(input);
if (lwadc_ptr->context_ptr == NULL) {
return FALSE;
}
adc_ptr = lwadc_ptr->context_ptr->adc_ptr;
ch_num = adc_ptr->HC1 & 0x1F;
if( ch_num != input )
adc_ptr->HC1 = ADC_CHANNEL(lwadc_ptr->input);
if ((adc_ptr->GC & ADC_GC_ADCO_MASK) == 0) {
/* ADC is not in continuous mode. */
adc_ptr->GC |= ADC_GC_ADCO_MASK;
}
sample = adc_ptr->R1;
*outSample = sample & ADC_CDR_CDATA_MASK;
return TRUE;
}
Note that:
Instead of replacing lwadc_vdac.c from thread/317081, what I did to make the ADC work was to comment out the next lines in _lwadc_init and just add the last line.
// enable clock for adc module
//if (_bsp_adc_io_init(init_ptr->ADC_NUMBER) != IO_OK)
//{
// return FALSE;
//}
_bsp_adc_io_init(init_ptr->ADC_NUMBER);
The problem is that the _bsp_adc_io_init is ALWAYS returning IO_ERR, so not checking the return value do the trick.
I just commenting this if you are using a MQX version closer to 4.0.
Next release 4.0.1 will be as the lwadc_vdac.c file already provided by Rene.