RS232 Communication Problem

Moderators: TomKerekes, dynomotion

Post Reply
ardagunay
Posts: 3
Joined: Wed Mar 15, 2023 9:52 pm

RS232 Communication Problem

Post by ardagunay » Wed Mar 15, 2023 10:15 pm

Hello,

Hello, I am using the Dynomotion KFLOP Kanalog expansion board for my thesis project. As part of my project, I am trying to process live data from an RPLIDAR A1M8 model through RS232. The connections are definitely correct, but when I try to collect the data, I only get zeros. Previously, I spent hours trying to solve the problem and got the code working, but as soon as turn off the system and open it again, I started getting all zeros again (even though I didn't change anything in the code). Currently, I am able to establish data flow and communication with the device using an updated code. When I request data such as health status from the device, it gives me the requested information. However, as soon as I give the "start scan" command, the device starts giving me all zeros. The LIDAR works flawlessly on its own. I saw a solution on the internet, such as "de-assert DTR line," but I don't know how to do it. I would appreciate it if you could support me on how to do it. Also, if there is any other reason for this problem, I would be very grateful if you could guide me towards a solution.

User avatar
TomKerekes
Posts: 2636
Joined: Mon Dec 04, 2017 1:49 am

Re: RS232 Communication Problem

Post by TomKerekes » Wed Mar 15, 2023 11:43 pm

Hi ardagunay,

What baud rate are you using? KFLOP checks for an input character every 90us which works out to 111,111 Baud. Not quite 115,200 Baud. Above that for more than a few characters then characters are likely to get dropped. I wouldn't expect all zeros. What did you do to make it work? Are you keeping track of what you are doing?

Do you have an oscilloscope or other monitor to see what is happening?
I saw a solution on the internet, such as "de-assert DTR line," but I don't know how to do it.
KFLOP doesn't support DTR and from what I found on-line the A1M8 doesn't seem to either.
Regards,

Tom Kerekes
Dynomotion, Inc.

ardagunay
Posts: 3
Joined: Wed Mar 15, 2023 9:52 pm

Re: RS232 Communication Problem

Post by ardagunay » Mon Mar 20, 2023 2:25 am

Hello Tom,

I am using 115200 as a baud rate. I changed code from the scratch and it did work for a while. After reseting device it started giving all zeros again. It happend twice so I have 3 codes that worked before but not working now. I don't have oscilloscope but i will find one. Also I want to add that old version of the code worked in the past as well. But it started giving all 0s after cutting power supply. Expected output is something like "A34C5" Here is the updated code: yeni 1.png, yeni 2.png, yeni 3.png Here is the older version of code: eski 1.png, eski 2.png
Attachments
yeni 1.png
yeni 2.png
yeni 3.png
eski 1.png
eski 2.png

User avatar
TomKerekes
Posts: 2636
Joined: Mon Dec 04, 2017 1:49 am

Re: RS232 Communication Problem

Post by TomKerekes » Mon Mar 20, 2023 2:49 pm

Hi ardagunay,

As I said 115,200 baud won’t work.

Post your programs with a description not images of your programs.

Indent your programs to make them readable.
Regards,

Tom Kerekes
Dynomotion, Inc.

ardagunay
Posts: 3
Joined: Wed Mar 15, 2023 9:52 pm

Re: RS232 Communication Problem

Post by ardagunay » Fri Mar 24, 2023 6:23 am

Hi Tom,

Now I am trying to establish communication again regarding your feedbacks. Serial communication test that i'm appliyng is added as a code below. As a result of thist test i am expecting outputs. Expected outputs are below as well as a jpeg file. I am getting all 0s instead of outputs. Am I missing something?

Kind Regards.

Current Test Code

Code: Select all

#include "KMotionDef.h"
#define RS232_BAUD_111111 ((16666666/111111/16)-1)
void wait90us() {
    float time = Time_sec();
    float  target_time = time + 0.00009;

    
   while (time < target_time) {
      time =  Time_sec();
    }
    
}
int i,t,f;
int kek;
int ExpLength = 100000;
unsigned char Scope02[100000];

main(){

    SetBitDirection(45,1);
    
     SetBitDirection(44,0);
			EnableRS232Cmds(RS232_BAUD_111111);
   FPGA(KAN_TRIG_REG) = 1;
    DoRS232Cmds = FALSE;
  
FILE *FilePointer1;
      char String1[256]; 
      
     while (pRS232RecIn == pRS232RecOut){
RS232_PutChar(0x40);

}

  for(i=0;i<2000;i++){
      WaitNextTimeSlice();
      }
      while (pRS232RecIn == pRS232RecOut){
RS232_PutChar(0x90);

}
      for(i=0;i<2000;i++){
      WaitNextTimeSlice();
      }
      
DAC(1,(int)-676);
       while (pRS232RecIn == pRS232RecOut){
RS232_PutChar(0xA5);
}  
while (pRS232RecIn == pRS232RecOut){
RS232_PutChar(0x21);
} 
SetStateBit(44,0);
for(t = 0; t<2000; t++){
 WaitNextTimeSlice();
 }
     

for(kek = 0; kek<ExpLength;kek++){

while (pRS232RecIn == pRS232RecOut)
;

Scope02[kek] = RS232_GetChar();

wait90us();

}

DAC(1,0);
       while (pRS232RecIn == pRS232RecOut){
RS232_PutChar(0x25);
}   

 FilePointer1=fopen("C:\\Users\\Arda\\Desktop\\ardaexps\\ardaexp17","wt");     
   
     
for(f=0;f<ExpLength;f++)                                  
    {
      fprintf(String1,"data %X\n",Scope02[f]);

      }
      
    fclose(FilePointer1);

}


Snippet from expected Results are attached. Also I want to add that I achieved that succesfull and desired result by using code provided below. But after closing and opening system again my program never worked. Old Working program

Code: Select all

#include "KMotionDef.h"
#define RS232_STATUS 0xc1 
#define RS232_DATA 0xc0 
#define RS232_DATA_READY 0x01 
#define RS232_TRANSMIT_FULL 0x02

void ReceiveChar()
{
while ((FPGA(RS232_STATUS) & 1)==0);
return FPGA(RS232_DATA);
}
void SC(char c)
{
    while (FPGA(RS232_STATUS) & RS232_TRANSMIT_FULL);
    unsigned char data = c;
    FPGA(RS232_DATA) = data;
}
int ExpLength = 50000;
double Scope02[100000];
double T0, dT, TNew, T1, Time, TOff,TOld;																														
double EndTime;
int M2;																													
int PrintingIndex;
int Ind;
int Counter = 0;
dT = 0.000360 ;
int i = 0;
unsigned char dis;
unsigned char ang;
double angle[50000];
double distance[50000];
main()
{
	SetBitDirection(45,1);
	FPGA(RS232_BAUD_REG) = RS232_BAUD_115200; 
	FPGA(KAN_TRIG_REG) = 1;	

	FILE *FilePointer1;
	char String1[256];
	char Str[10];
	
	T0 = Time_sec();                                                
    TOld = Time_sec();
	EndTime = 60;	
	
	DAC(1,0);
	
	for (Ind = 0; Ind<ExpLength; Ind = Ind+1)

	{   
		Time = Time_sec()-T0;
        TNew = Time_sec();											
       
		if (Time>EndTime)
		{
    		DAC(1,0);
			SC(0x25);    		
			break;		
		}

		
		M2 = (int)(-675.8);	
		DAC(1,M2);
		SC(0x21);
		
	while((FPGA(RS232_STATUS) & RS232_DATA_READY) == 0){
	Scope02[Counter] = ReceiveChar();
	
 		}
 			
		
		Counter = Counter+1;		
		WaitNextTimeSlice();
	
}		
	DAC(1,0);  	
	SC(0x25);
		FilePointer1=fopen("C:\\Users\\student\\Desktop\\arda\\ardaexp1","wt");     
	for(PrintingIndex=0;PrintingIndex<ExpLength;PrintingIndex=PrintingIndex+1)						
    {
    	
    	   	fprintf(String1,"%X \n",Scope02[PrintingIndex+30]);
			
}
	fclose(FilePointer1);
	
}

Attachments
test.png

User avatar
TomKerekes
Posts: 2636
Joined: Mon Dec 04, 2017 1:49 am

Re: RS232 Communication Problem

Post by TomKerekes » Fri Mar 24, 2023 7:06 pm

Were you able to change the transmitting device's Baud rate? Both sides need to be set at the same rate.

Please indent your code consistently and add comments explaing what you are doing. That's only a common courtesy if you are asking others to check your code for you.

KFLOP User Threads are basically limited to 64KBytes/Thread (code and global data). The Stack size (local variables) is limited to 2KBytes.

An Array like:

Code: Select all

double Scope02[100000];
will use 8x100000 = 800,000 bytes. What is this needed for?

The gather_buffer is an array of 1 million doubles. You might use that if large arrays are required.
Regards,

Tom Kerekes
Dynomotion, Inc.

Post Reply