Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

Read serial port and plot Matlab graph - some characters are missing, why?

Altera_Forum
Honored Contributor II
1,293 Views

Hi all, 

 

I was trying to access serial port data sent from UART in Altera Nios II to plot graph real time in Matlab. 

 

I wanted to plot the graph in the format of: (in Matlab code) 

 

a = str2double(line(1:2)); %a ranged from 1 to 12 

b = str2double(line(4:7)); %b is 4 digits 

c = str2double(line(9:10)); %c ranged from 1 to 12 

 

Example, 01@2564;12 , so line 3 is for character @ and line 8 is for character ; 

 

In the C code, I do something like: 

 

int MAT1[]={0,1,10, arr[3], arr[2], arr[1],arr[0],-1,arr_index[1],arr_index[0]}; // so 10 is for character @ and -1 is for character ; 

 

for ( i = 0 ; i < 10 ; i++ ) txdata1 = mat1 

 

When I plot the graph and save it in .csv, from the excel column, correct c should be '02' but it shows only the first digit '0', how can I write the code in C to represent the ascii character so that it will display properly '2' instead of '0'? 

 

My second question is, it appears to me that, the other possibility of getting the above error is that, the uart is only able to send the first digit instead of two digits that is why it shows only '1' when it is supposed to display '12' for c? Because, in a few occasions,I did see it display '12'  

 

I hope someone can give me a hint of how to solve this problem, thank you in advance
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
354 Views

 

--- Quote Start ---  

Hi all, 

 

I was trying to access serial port data sent from UART in Altera Nios II to plot graph real time in Matlab. 

 

I wanted to plot the graph in the format of: (in Matlab code) 

 

a = str2double(line(1:2)); %a ranged from 1 to 12 

b = str2double(line(4:7)); %b is 4 digits 

c = str2double(line(9:10)); %c ranged from 1 to 12 

 

Example, 01@2564;12 , so line 3 is for character @ and line 8 is for character ; 

 

In the C code, I do something like: 

 

int MAT1[]={0,1,10, arr[3], arr[2], arr[1],arr[0],-1,arr_index[1],arr_index[0]}; // so 10 is for character @ and -1 is for character ; 

 

for ( i = 0 ; i < 10 ; i++ ) txdata1 = mat1 

 

When I plot the graph and save it in .csv, from the excel column, correct c should be '02' but it shows only the first digit '0', how can I write the code in C to represent the ascii character so that it will display properly '2' instead of '0'? 

 

My second question is, it appears to me that, the other possibility of getting the above error is that, the uart is only able to send the first digit instead of two digits that is why it shows only '1' when it is supposed to display '12' for c? Because, in a few occasions,I did see it display '12'  

 

I hope someone can give me a hint of how to solve this problem, thank you in advance 

--- Quote End ---  

 

 

anyone please? any hint will do for me to try?
0 Kudos
Reply