Prev: matlab - Warning: Infinite or Not-a-Number function valueencountered.
Next: Using a loop on a function,sum vectors of different sizes
From: Kimji on 31 Mar 2010 12:47 Hello! I am working on a matlab project now that communicates with a device (an fpga) via rs232. The configuration is 8 data bits, no parity bits, 1 stop bit and the baud rate is 115200. Now my device is sending 8 bits to the computer and I plot the data. The problem is that matlab reads the data differently. In the 8 bits that the fpga sends, the most significant bit is the sign bit (for negative values) while bits 6 to 0 is the value. There isn't any problem with the positive values but I'm having problems with the negative values. For example, when the fpga sends 127, the binary input to the computer is 01111111. When data is -127, the binary input to the computer is 10000001, which matlab converts to decimal as 1. Similarly, when the fpga sends 1, binary input is 00000001 while if -1, binary input is 11111111 which matlab reads as 127. So is there any way I could configure matlab to read the negative values correctly? I am using the fread command to read data from the rs232. I have tried specifying the precision to 'schar' as matlab help says it's a signed 8-bit character type but it seems like matlab ignores the sign bit and reads only bits 6 to 0. I have also tried 'char' and 'int8' but I get the same result as using 'schar'. Thanks! |