NHS3152 ADC issue

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

NHS3152 ADC issue

跳至解决方案
1,962 次查看
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 项奖励
回复
1 解答
1,689 次查看
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.

在原帖中查看解决方案

4 回复数
1,690 次查看
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,689 次查看
tillostermann
Contributor II

Hi Dries,

thank you, that resolved the problem.

BR

Till

0 项奖励
回复
1,689 次查看
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 项奖励
回复
1,689 次查看
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 项奖励
回复