Why does the CIR data I reading like this?

Hello,everyone.
I’m got some trouble when reading the CIR data form DWM1000 module.I used MSP430F5438 as a controller and referred to the program of dwt_readaccdata(uint8 *buffer, uint16 len, uint16 bufferoffset) to read the CIR data, but the data returned was always like this, or a similar waveform with a certain delay. I have checked for a long time, but I have not been able to find the problem.


The basic configuration of the module is as follows:
Channel:1
DataRate:6.8M
PRF:16M
The procedures for turning the clock on and off for register 0x36:00 are as follows:

int getready_readCIR()
{
int SJL;
if(dw_configure.PRF==16)
{
SJL=3968;
}
else //else if(dw_configure.PRF==64)
{
SJL=4064;
}

P3OUT &=~BIT0;
Write(4,load3600kaibuf);  //unsigned char load3600kaibuf[4]={0xF6,0x00,0x44,0x82}; 
                                             //FACE=1,RXCLKS=01,AMCE=1, 
P3OUT |=BIT0;
DelayNus(1);

return SJL;

}

void finish_readCIR()
{
P3OUT &=~BIT0;
Write(4,load3600guanbuf); //unsigned char load3600guanbuf[4]={0xF6,0x00,0x00,0x02};
//FACE=0,RXCLKS=00,AMCE=0,
P3OUT |=BIT0;
DelayNus(1);
}

Since the MSP430 has limited RAM and cannot set an excessively large cache array, I modified the program to read the CIR to only read the CIR data of one sample per cycle, and the specific procedure is as follows:

void read_CIR(int hang)
{
int j;
unsigned char FWCIR[4][4];

for(j=0;j<4;j++)
{
	FWCIR[j][0]=0x65;  //read form 0x25  
	if(hang%128==0)  
	{
		FWCIR[j][1]=0x80;  
		if(hang/128==0)  
		{
			FWCIR[j][2]=0x00;
		}
		else  
		{
			FWCIR[j][2]=(unsigned char)(hang/128);  
		}
	}
	else  
	{
		FWCIR[j][1]=0x80 | (unsigned char)(hang%128);  
		FWCIR[j][2]=(unsigned char)(hang/128);  
	}
	hang+=1;  
}

int m,n;
for(m=0;m<4;m++)  
{
	unsigned char Temp[4];  

	for(n=0;n<4;n++)  
	{
		Temp[n]=FWCIR[m][n];  
	}

	P3OUT &=~BIT0;
	pan(Temp);  
	Read(4,Temp);  
	P3OUT |=BIT0;
	DelayNus(1);

	switch(m)  
	{
	  case 0:
	  {
	      Lrealpart=rbuf[0];  
	  }; break;
	  case 1:
	  {
	      Hrealpart=rbuf[0];  
	  }; break;
	  case 2:
	  {
	      Limaginarypart=rbuf[0];  
	  }; break;
	  case 3:
	  {
	      Himaginarypart=rbuf[0];  
	  }; break;
	  default: ; break;
	}
}

}

(It should be noted that using the Read() function will store the valid data read into the rbuf variable in turn.)

The procedure for using the serial port to access CIR data and return it in real time is as follows:

void msp_to_pc(void)
{
int i,JJ;

WDTCTL = WDTPW+WDTHOLD;  
P3SEL |= BIT4+BIT5;  
P3DIR |= BIT4;  
                
UCA0CTL1 |= UCSWRST;  
UCA0CTL0 = 0x00;  
UCA0CTL1 |= UCSSEL_2;  
UCA0BR0 = 0X8A;  
UCA0BR1 = 0X00;  
UCA0MCTL = UCBRS_7+UCBRF_0;   
UCA0CTL1 &= ~UCSWRST;  

getready_readCIR();  

for(i=0;i<SJL;i+=4)
{
	read_CIR(i);  
	FINAL_data[0]=Lrealpart;  
	FINAL_data[1]=Hrealpart;  
	FINAL_data[2]=Limaginarypart;  
	FINAL_data[3]=Himaginarypart;  

	for(JJ=0;JJ<4;JJ++)
	{
	    UCA0TXBUF = FINAL_data[JJ];  
	    DelayNms(1);  
	    while(!(UCA0IFG & UCTXIFG));  
	}
}
fasongbaoshu++;

finish_readCIR();  

}

In addition to the basic configuration of the main() function, the following procedures are used for ranging and accessing CIR data:

while(1)
{
    for(anchor_num=1;anchor_num<2;anchor_num++) //For single anchor
    {
    	flag1=youxiaocejucishu;  //Mark1
        tx_rx();  //two-way ranging process
        cejucishu++;  //Mark2
        if (flag1!=youxiaocejucishu)  //correct two-way raging
        {
        	msp_to_pc();  
        }
    }

    cejuzushu++;  //Mark3
}

The general situation is like the above, if you have any suggestions for the above questions, please be sure to leave a message to me, thank you very much!

As noted in the user manual when reading CIR data the first byte is always padding. You must read one byte more than you need and then discard the first byte received. It doesn’t look like your code is doing that.

Hi, AndyA. Thank you very much for your reply. Due to the memory limitations of the MSP430 controller, I had to read the data for 8bits per sub-index in turn. I referred to Figure 6 and Figure 7 on page 13 of the user manual, and used a circular approach to construct access instructions for each sub-index in the 0x25 register. The function pan() I defined is used to determine how many octet headers does the read instruction has, i.e., which case corresponds to Figure 2~7 of the user manual. The function Read() is used to read the data of the corresponding register and return the data via rbuf. What puzzles me is that the user manual mentions that the first octet received needs to be discarded regardless of which sub-index the read begins at. With a strategy like the one I built that reads each sub-index, should I discard the first byte when I receive the data from each sub-index of each sample, or is it something else?

In addition, I used MATLAB to write a serial receiver program, and each sample, i.e., four bytes of data, was processed and stored once. The previous CIR image was drawn by jieguo(1).

clear all;
global s;
global data;
global dataout;

delete(instrfindall);
s=serial(‘COM9’);
s.BytesAvailableFcnMode=‘byte’;
s.InputBuffersize=4096;
s.OutputBuffersize=1024;
s.BytesAvailableFcnCount=4;
s.TimeOut=20;
s.BaudRate=115200;
s.Parity=‘none’;
s.DataBits=8;
s.StopBits=1;
s.ReadAsyncMode=‘continuous’;
s.BytesAvailableFcn=@my_callback;
fopen(s);

function=my_callback(obj,event)
global s;
global data;
global dataout;
global jieguo;

    data=zeros(100,1);
    data=fread(s,4,'uint8');  
    dataout=zeros(2,1);  
    jieguo=zeros(2,1);  
    for i=1:2
        dataout(i)=256*data(2*i)+data(2*i-1);  
    end      
    jieguo(1)=sqrt((dataout(1))^2+(dataout(2))^2);  
    %jieguo(1)=max(dataout(1),dataout(2))+0.25*min(dataout(1),dataout(2));  
    jieguo(2)=atan2(dataout(2),dataout(1));     
    fid = fopen('read_CIR_2024_1_19.txt','a+');     
    fprintf(fid,'%.3f\r\n',jieguo(1));  
    fclose(fid);

end

Yes. You must read at least two bytes for each sub index if you want one byte at a time.

thanks for sharing . I was also facing the same issue.

Thank you very much for your reply, I’ll try and hope to get the right result soon.

Good luck and hopefully we can all get the right results as soon as possible.

Hi AndyA, thank you very much for the hint you gave me earlier, when I read the data from the second byte (rbuf[1]) fed back by the Read() function, the CIR features loomed until I gave data=fread(s,4,‘uint8’) in the serial port callback program to data=fread(s,4,‘int8’), and I got the correct CIR data.
Very happy and thank you again for your previous reply.