cancel
Showing results for 
Search instead for 
Did you mean: 

Sampling sound and sending it using RF, sending takes to much time

KD�?b
Associate II

Hello,

I am having a problem. I am using STM32F411CE and NRF24L01 module. I try to sample sound using ADC and then I send it using RF to another uC. I sample a simple sine wave at 48kHz with 16 bit resolution using IT. I send 32 bytes at one time using RF module so i can send 16 samples at one time cause 1 sample is 16 bit (2 bytes). When i get enough samples the flag is up and in the main there is a function that send the data. When I gather test data in the ADC interrupt i can see a nice sine wave so i know that the ADC is working properly.

0693W0000059A0yQAE.jpg 

But when I take te test data in main where I send the data i can see that the sine wave is chopped.0693W0000059A67QAE.jpgI am using HAL libraries and the RF module library i found online.

The main code

	if (adcReadFlag == true)
		{	
				if(NRF24_write(Data_1,32))
                                adcReadFlag = false;
 
			        for(int i=0;i<16;i++)
					{
					test[n]=((Data_1[i*2] << 8) | (Data_1[i*2+1] & 0xff))*8 ;
					if(n<1000)n++;
					}
					
		}
		

Interrupt code

        temp=HAL_ADC_GetValue(&hadc1);
	Data_1[i*2] = ((temp & mask_L) >> 8);
	Data_1[i*2+1] = (temp & mask_R);			
	i++;
	if (i==16)
	{
		i=0;
		adcReadFlag=true;
	}

I tried sending data with and without acknowledgement. Is it possible that sending takes that much time and I miss some samples? How can I solve this problem if so.

I would apreaciate some help. Thank you

4 REPLIES 4
TDK
Guru

How quickly are sending data?

Your chunks of sine wave readings are not multiples of 16. Seems like they should be if you're sending 16 readings at a time.

If you feel a post has answered your question, please click "Accept as Solution".
MM..1
Chief III

Hmm your idea will dont work. You need one process ofload of MCU. Better for offloading is ADC when use DMA.

Use half and full complete callbacks to send data. But realy i mean RF not have required throughput. 48kHz 16bit one channel need 768kbit-s

KD�?b
Associate II

I tried at first sending samples with 8 bit resolution and the result was quite similar. In documentation it says that this module has 2Mbs air data rate and I am using that speed. I know it is theoretical but for now I try to sample one channel and obtain on the reciver side quite the same sine wave. I will try to use DMA for sampling. But still I do not now why the signal is in 8 sample chunks.

MM..1
Chief III

Your idea FOR 0..15 is bad because dta is overwrited with ADC interrupt in same time when is send to RF.

You need buffer 32 and start sending 0..15 when 16 arived , but ADC continue to index 31 and after this second stage send 16..31 and ADC from 0.

DMA circular do it for you without use an MCU instruction time, but same technique you can use with IT.

Or when 16 then 0..7 and 8..15 ...

AND please define data array as 16 bit and remove all >>8