NHS3152 ADC issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NHS3152 ADC issue

Jump to solution
1,417 Views
tillostermann
Contributor II

Hi,

the following code always gives 0 as adc_input (after the first loop):

#include "board.h"
#include "../mods/uarttx/uarttx.h"

int main(void)
{
    // Init board
    Board_Init();

    // Init ADC
    Chip_ADCDAC_Init(NSS_ADCDAC0);
    Chip_ADCDAC_SetMuxADC(NSS_ADCDAC0, ADCDAC_IO_ANA0_0);
    Chip_ADCDAC_SetInputRangeADC(NSS_ADCDAC0, ADCDAC_INPUTRANGE_WIDE);
    Chip_ADCDAC_SetModeADC(NSS_ADCDAC0, ADCDAC_SINGLE_SHOT);
    volatile int adcInput=99;

    /* Blink with a period of 250ms+250ms, or 2Hz */
    while (1) {
        // Toggle LED
        LED_Toggle(LED_RED);

        // Read out ADC
        Chip_ADCDAC_StartADC(NSS_ADCDAC0);
        while (!(Chip_ADCDAC_ReadStatus(NSS_ADCDAC0) & ADCDAC_STATUS_ADC_DONE)) { /* wait */ }
        adcInput = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);

        // UART print to give out data
        UartTx_Init();
        UartTx_Printf("ADC:%d\n", adcInput);
        UartTx_DeInit();

        // Pause
        Chip_Clock_System_BusyWait_ms(250);
    }
    return 0;
}

I've disabled code optimization in the preferences and double checked that there is ~1V at the ADCDAC_IO_ANA0_0 of the NHS3152 demo board.

What am I missing? Help appreciated.

BR

Till

0 Kudos
1 Solution
1,144 Views
driesmoors
NXP Employee
NXP Employee

Hi,

It seems that in the SDK example, a line mysteriously disappeared.

Can you add this line and try again?

Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_5, IOCON_FUNC_1);

From the user manual UM10876:

pastedImage_2.png

and:

pastedImage_1.png

I'll make sure a future SDK release restores this line - truly sorry for this hickup!

Best,
Dries.

View solution in original post

4 Replies
1,145 Views
driesmoors
NXP Employee
NXP Employee

Hi,

It seems that in the SDK example, a line mysteriously disappeared.

Can you add this line and try again?

Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_5, IOCON_FUNC_1);

From the user manual UM10876:

pastedImage_2.png

and:

pastedImage_1.png

I'll make sure a future SDK release restores this line - truly sorry for this hickup!

Best,
Dries.

1,144 Views
tillostermann
Contributor II

Hi Dries,

thank you, that resolved the problem.

BR

Till

0 Kudos
1,144 Views
tillostermann
Contributor II

In the function:

int Chip_ADCDAC_GetValueADC(NSS_ADCDAC_T *pADCDAC)
{
    return pADCDAC->ADCDR & ADCDAC_ADC_VALUE_MASK;
}

I get the error:

error_screenshot_3.png

Multiple errors reported.

1) Failed to execute MI command:
-var-update 1 var2
Error message from debugger back end:
value has been optimized out

What can I do to fix it? Compiler optimization is already deactivated.

BR

Till

0 Kudos
1,144 Views
tillostermann
Contributor II

Half fix: I found that the function:

int Chip_ADCDAC_GetValueADC(NSS_ADCDAC_T *pADCDAC)
{
    return pADCDAC->ADCDR & ADCDAC_ADC_VALUE_MASK;
}

was located outside of the project and was therefore optimized.

Nevertheless, the example code does not work. Is the ADC section buggy, there is also another open question on this?

https://community.nxp.com/message/1025268?q=nhs31 

Help really appreciated!

0 Kudos