This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why NRF24LE1 ADC is reading value always as 255?

I am doing a register retention gzll transmit code with ADC. But problem is that the ADC value transmitted is always 255, if I connect ground to ADC it would read 247. Why is there such a problem here. Here is my code:

#include"reg24le1.h" // I/O header file for NRF24LE1
//#include"hal_uart.h" // library containing serial communication functions
#include"hal_delay.h" // header file containing delay functions
#include"hal_clk.h"
#include <stdio.h>
#include "nrf24le1.h"
#include "gzll_mcu.h"
#include "gzll.h"
#include "hal_adc.h"

// Repeated putchar to print a string
/*void putstring(char *s)
{
  while(*s != 0)
     hal_uart_putchar(*s++);
}*/
 int gzlinit=0,val=0;
 uint8_t payload[3];
 void wakeup_irq() interrupt INTERRUPT_WUOPIRQ
{
	;//putstring("Hello Ranjan I woke up\n");
	//gzlinit=1;
}
// main function
void main()
{
	//hal_clklf_set_source(HAL_CLKLF_XOSC16M_SYNTH);
	//hal_clk_set_input(HAL_CLK_XOSC16_OR_RCOSC16);
	 mcu_init();
  gzll_init();
	
	//hal_clk_set_freq(HAL_CLK_125KHZ); //if you put in 125Khz then uart wont work
		WUOPC0 = 0x02;

P01 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;

P0DIR = 0x02;
//P0DIR = 0xf2;//0x02 only for pin wake up 0xF2 both for uart and pin wake up
P1DIR = 0x00;
P2DIR = 0x00;
P3DIR = 0x00;


// Initializes the UART
 // hal_uart_init(UART_BAUD_9K6);
 hal_adc_set_input_channel(HAL_ADC_INP_AIN6);
  hal_adc_set_reference(HAL_ADC_REF_VDD);
  hal_adc_set_input_mode(HAL_ADC_SINGLE);
  hal_adc_set_conversion_mode(HAL_ADC_CONTINOUS);
	//hal_adc_set_conversion_mode(HAL_ADC_SINGLE_STEP);
  hal_adc_set_sampling_rate(HAL_ADC_2KSPS);
  hal_adc_set_resolution(HAL_ADC_RES_8BIT);
  hal_adc_set_data_just(HAL_ADC_JUST_RIGHT);
// Enable global interrupts
	IEN1 = 0x08;
  EA = 1;
	//MISC=1;
	hal_adc_start();
	PWRDWN = 0x04;
			// Clear power down
	PWRDWN = 0x00;
 //putstring("\r\nHello Init!!\r\n") ;
// delay_ms(2000);
  
//infinite loop
while(1)
{
// Print "Hello Everyone"
//putstring("\r\nHello Everyone!!\r\n") ;
//delay_ms(1000); // delay of 1sec
	
	while(P01==1)
		{
			//if(gzlinit==0)
			{
				PWRDWN=0x07;
			//gzll_init();
  
		
    if(gzll_get_state() == GZLL_IDLE)
    {
			while( hal_adc_busy() )                         // Wait for the ADC to finish a conversion
    {
		}
			val = hal_adc_read_LSB();
      payload[0] = val;
      // Transmits payload[] to pipe 0 address
      gzll_tx_data(payload, 3, 0);
      //gzlinit=2;			
    }	
			gzll_goto_idle();
	
			//putstring("\r\nHello Everyone!!\r\n") ;
			//if(gzlinit==2)
	    //break;
		}
	}
		gzlinit=0;
		// Register retention mode
			PWRDWN = 0x04;
			// Clear power down
			PWRDWN = 0x00;
	}
}

Parents Reply
  • This is a classic debug problem, you must try and fail a bit to learn, you don't have to ask a question every time something is not working. Have you tried other analog input pins using the sdk example? Have you checked that there is no other functionality enabled for the pin you are using (e.g. jtag, uart, gpint, etc). 

    A value of 255 means that you are either using the wrong pin, something is forcing the pin high, or there is a configuration issue. The recommendation is to use the example in the sdk and do as small changes as possible to check the different analog input pins.

Children
Related