This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Having problems developing a code for data acquisition with 12-bit adc using nrf24le1

I have a fully functional code for 8-bit data acquisition using nrf24le1. Now i want to upgrade it to 12-bit resolution ,but i have problems in doing so .

In my project i am trying to read electrical signals through 7 channels using nrf24le1, this acquired data is sent wireless through a radio with a channel frequency of 2.4GHz and finally the signal is read in a computer. This is my code for 12-bit resolution and my errors: transmitter code:

/* Code for the transmitter: contains 2 continuous A/D conversion and transmit to base station, 2 bytes per packet.

*/ #include <Nordic\reg24le1.h> #include <stdint.h> #include "hal_nrf_hw.h" //#include "MyCustom.h" #include "hal_nrf.h" #include "hal_adc.h"

#define SAMPLING_INTERVAL_US 10000 //sampling rate is 10^6 / 10000 #define CHANNEL_NUMBER 7 #define PAYLOAD_LUMPS 3

#define TIMER_RELOAD_LSB (uint8_t)(0x10000-((SAMPLING_INTERVAL_US/3)*4)) #define TIMER_RELOAD_MSB (uint8_t)((0x10000 -((SAMPLING_INTERVAL_US/3)*4))>>8)

uint8_t adc_data_lsb;
uint16_t rf_payload[CHANNEL_NUMBER * PAYLOAD_LUMPS];//changing the Channel_number to payload_size uint16_t dummy[CHANNEL_NUMBER * PAYLOAD_LUMPS]; uint8_t i, timer_set;
uint8_t timerSet = 0;

// ADC initialization void adc_init() { hal_adc_set_input_channel(HAL_ADC_INP_AIN0);
hal_adc_set_reference(HAL_ADC_REF_VDD);
hal_adc_set_input_mode(HAL_ADC_SINGLE); // can be changed to differential hal_adc_set_conversion_mode(HAL_ADC_SINGLE_STEP); hal_adc_set_resolution(HAL_ADC_RES_12BIT);
hal_adc_set_data_just(HAL_ADC_JUST_RIGHT);
}

void main() {
uint8_t i, j; // Variable declarations.

//P3DIR = 0x00;

// Initialize the ADC.
adc_init();

// 1. To use the radio the radio clock must be enabled.
RFCKEN = 1;

TMOD = 0x01;  // Timer 0 mode 1, 16-bit mode
TR0 = 1;      // Start timer 0
ET0 = 1;      // Enable timer 0 interrupt

// 2. If the RF interrupt should be used, remember to set both the global interrupt enable flag and the RF interrupt enable flag.
RF = 1;  
EA = 1;



// 3. By default the radio will be in PTX mode, and powered down. The last thing needed is to power it up before it is ready for use. 
hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
//hal_nrf_enable_continious_wave (1)	;

// P0DIR = 0x00; // P0DIR = 0xFF;

while(1)
{
	for( i =0; i < PAYLOAD_LUMPS; i++ )
	{
		while(!timerSet);
		timerSet = 0;
		//Main ADC sampling code
		for( j = 0; j < CHANNEL_NUMBER; j++ )
		{
			hal_adc_set_input_channel(i);
			hal_adc_start();
			while( hal_adc_busy() );
			  
			rf_payload[j+i*CHANNEL_NUMBER] = hal_adc_read_LSB();
   // rf_payload[j+i*CHANNEL_NUMBER] +=((unit16_t)hal_adc_read_MSB()) << 8;				
    dummy[j+i*CHANNEL_NUMBER] = (((uint16_t)hal_adc_read_MSB())<<8);
    	rf_payload[j+i*CHANNEL_NUMBER] = rf_payload[j+i*CHANNEL_NUMBER] + dummy[j+i*CHANNEL_NUMBER];		
   }

} hal_nrf_write_tx_payload(rf_payload, CHANNEL_NUMBER * PAYLOAD_LUMPS); CE_PULSE(); }
} void timer0_irq() interrupt INTERRUPT_T0 { TL0 = TIMER_RELOAD_LSB; TH0 = TIMER_RELOAD_MSB; timerSet = 1; }

// It is recommended to use an interrupt to receive data sent (TX_DS), // data received (RX_DR) or max retransmit (MAX_RT) messages from the radio. void rf_irq() interrupt INTERRUPT_RFIRQ { // Read and clear IRQ flags from radio uint8_t irq_flags = hal_nrf_get_clear_irq_flags(); switch(irq_flags) { // Transmission success case (1 << HAL_NRF_TX_DS): //radio_busy = false; // Data has been sent break; // Transmission failed (maximum re-transmits) case (1 << HAL_NRF_MAX_RT): // When a MAX_RT interrupt occurs the TX payload will not be removed from the TX FIFO. // If the packet is to be discarded this must be done manually by flushing the TX FIFO. // Alternatively, CE_PULSE() can be called re-starting transmission of the payload. // (Will only be possible after the radio irq flags are cleared) hal_nrf_flush_tx(); //radio_busy = false; break; } }

ERRORS:

SEGMENT: ?DT?_HAL_NRF_SET_RF_CHANNEL?HAL_NRF
LENGTH:  0001H

*** ERROR L107: ADDRESS SPACE OVERFLOW SPACE: DATA
SEGMENT: ?DT?_HAL_NRF_SETUP_DYNAMIC_PAYLOAD?HAL_NRF LENGTH: 0001H Program Size: data=164.0 xdata=0 code=2301 Target not created

RECEIVER CODE:

/* Code for the receiver: should be a continuous receiver that transmit the received packets to a PC through a UART communication. */ #include <stdio.h> #include <Nordic\reg24le1.h> #include <stdint.h> #include "hal_nrf_hw.h" //#include "MyCustom.h" #include "hal_uart.h" #include "hal_nrf.h"

#define CHANNEL_NUMBER 7 #define PAYLOAD_LUMPS 3 //#define PAYLOAD_SIZE 8 // difining a payload size different than channel_number

// Variable declarations. uint8_t rf_status; uint8_t rf_payload[CHANNEL_NUMBER * PAYLOAD_LUMPS]; uint8_t dataready = 0; bit data_received = 0;

void main() { uint8_t i; // uint8_t cnt, i = 0; // Enable RF interrupt and activate the global interrupt flag. RF = 1;
EA = 1;

RFCKEN = 1;

// 1. By default the radio will be in PTX mode. This means we need to active PRX mode to use it as a receiver.
hal_nrf_set_operation_mode(HAL_NRF_PRX);

// 2. With the default settings Pipe 0 will be used to receive incomming packets. For the radio to receive the packets sent by
// project 03 it is important to configure the Pipe 0 with the right payload length (3 bytes).
hal_nrf_set_rx_payload_width(0, CHANNEL_NUMBER * PAYLOAD_LUMPS);


// Power up the radio.
hal_nrf_set_power_mode(HAL_NRF_PWR_UP);

// hal_nrf_enable_continious_wave (1) ;

// 3. To enable the receiver the Chip Enable signal should be set high permantently. 
RFCE = 1;

//Setup the UART pins as outputs

// P0DIR = 0xDF; // P0DIR = 0xDF; P0DIR = 0x00;

// Init UART
//hal_uart_init();
hal_uart_init(UART_BAUD_38K4);


while(1)
{
if( data_received )
{
  for( i = 0; i < CHANNEL_NUMBER * PAYLOAD_LUMPS; i++)
    hal_uart_putchar(rf_payload[i]);

  data_received = 0;
}   

} }

// if(cnt = hal_uart_chars_available()) // { // for( i = 0; i < cnt; i++) // hal_uart_putchar( i ); // }

// } //}

// It is recommended to use an interrupt to receive data sent (TX_DS), // data received (RX_DR) or max retransmit (MAX_RT) messages from the radio. void rf_irq() interrupt INTERRUPT_RFIRQ { //uint8_t i; //payload_counter = (payload_counter+1)%2; // 4. The status of the interrupt flags should be read out and stored in the "rf_status" variable.
rf_status = hal_nrf_get_clear_irq_flags();

// It is common to use a switch to check which of the RF status bits were set. 
// Since this example will only be used as a receiver we should only expect RX_DR interrupts, but the other interrupts
// are included for reference.
switch( rf_status ) 
{
	case (1<<HAL_NRF_RX_DR):
		// 5. The RF payload must be read out and put in a buffer.
		hal_nrf_read_rx_payload(rf_payload);

// for( i = 0; i < CHANNEL_NUMBER * PAYLOAD_LUMPS; i++) // for( i = 0; i < CHANNEL_NUMBER * PAYLOAD_LUMPS; i++) // hal_uart_putchar(rf_payload[i]); data_received = 1;

		break;

	
	// A packet was sent.
	case (1<<HAL_NRF_TX_DS):
		break;
	
	// A packet was sent, but no acknowledge was received. 
	case (1<<HAL_NRF_MAX_RT):
		break;
}

}

  • I am happy to take a look at your code, but could you please include it as an attachment instead? The formatting seems to have failed in the post. If you just zip the entire project folder, including source and project files, I should be able to compile and test your code easily.

  • Also, there is not much gain using the 12-bit mode in the nRF24LE1 as the ADC doesn't have the dynamic range to utilize it. 10-bit of resolution is about as much as you can get (the 2 extra bits are basically just noise).

Related