Hello,
I'm trying to send some characters to my STM32f303 microcontroller but I'm getting wrong datas on the microcontroller side.
Here is my JavaFX 8 Proje Code:
public void sendClick(ActionEvent event) throws FTDIException,UnsupportedEncodingException{
int deviceCount;
int que = 0;
int eepromRead = 0;
String descrip = "";
byte[] read = new byte[200];
byte[] write = new byte[20];
if (ftdi.getDevices().length > 0) {
dev = ftdi.getDevices()[0];
try {
dev.open();
System.out.println("Device is opening.");
try {
dev.setBaudRate(19200);
} catch (FTDIException e) {
// TODO: handle exception
System.out.println("Baundrate Ayarlanamadi");
}
write = txtInput.getText().getBytes("ISO-8859-1");
descrip = dev.getDescription();
dev.write(write,write.length);
que = dev.getQueueStatus();
ftdiLbl.setText("Lenght of the info: " + String.valueOf(write.length) +" " + "\n"
+ write + "\n"
+ "Queue: " + String.valueOf(que));
//dev.read(read);
//txtRecieved.appendText(read.toString());
txtRecieved.setText(descrip);
}
finally {
System.out.println("Device is closing.");
dev.close();
}
}
}
And here are the some SS:
https://www.dropbox.com/s/v7rpjepaet9hta8/Char_a.PNG?dl=0
https://www.dropbox.com/s/0myfniwh5e356ym/char_b.PNG?dl=0
https://www.dropbox.com/s/edhhwmawhi8gms4/String_fefe.PNG?dl=0
I'm sending 'a' from the PC side, on the microcontroller side this character read as 0x06.
Same as 'b' is reading 0x18
fefe is reading "xfxf"
How can I solve this issue?
Best Regards,
NAZIM YILDIZ
Hi Nazim,
I have tested the code using an FTDI cable with TX connected to RX (i.e. loopback).
Calls to setBaudRate and write worked ok. Bit widths checked out, was definitely sending @19200. Tried write with single and multiple bytes in the array. That worked correctly.
I did find a bug in the native code for read. This has been corrected in r23.
Are you building the native library from source?
Regards,
Stephen
I did not build native library. I downloaded FTDIInterface.dll and yad2xxJava-0.2-SNAPSHOT.jar under Files->REL-0.2 path. Then copied dll file at C:\Windows\System32 path.
I also opened a topic on http://www.coderanch.com/t/643384/JavaFX/java/JavaFX-FT-Serial-Communication this forum. I'm giving another example there. I'm sending 2 bytes directly which are 0x61 and 0x62 but they are received wrong from micro side.
Should I build last pushed files to fix this issue?
Note: I was worked with http://bleyer.org/jd2xx/ dll 1 year ago, I did not faced any communication issue. I'm using the same hardware like one year ago just software(Java 7 to JavaFX 8, and FT232 library) is changed.
Do you have either a digital storage oscilloscope or logic state analyser available? I used both for my testing and they both checked out ok.
On the microcontroller end are you getting any errors, i.e. framing or overrun? Is the baud rate generator set correctly? One off, bit rate doubling/halving, incorrect number of bits and wrong parity are common problems. Have you tried sending from the micro and capturing the output on a scope or logic analyser?
r23 files will not fix this issue. Bug was in the read method i.e. receiving. Sending code works just fine.
If jd2xx code worked previously then perhaps you should give that a try.
Yes I'm sure baud rate is setted correctly I was not looked Status Register about framing, overrun erros... I'll check them. Also I'll look FT232 TX pin with logic analyzer.
I'm not sure about equality off parity, stop and data lenght between PC and micro sides. In these
demos microcontroller side parity = "None", stop bit = "1" and data lenght is 8 bits but I did not configure these parameteres on PC side.
How can I set parity and stop bits on PC side? by setBitMode(byte pinDirection, FTDIBitMode bitMode) method?
Hi,
the FTDI device I am testing with defaults to 8 bit, 1 stop bit, no parity. With the v0.2 release you have no control over these settings.
I have added more functions over the weekend, Device.setDataCharacteristics can be used to set parity, bits and stop bits. The Function Index wiki page lists all of the D2XX functions and release level they became available.
Hi Stephen,
I did some work and I noticed that on the micro side I'm getting framing error as you mention before.
I checked baud rates with scope and it seems no problem. I cant work enough with this issue because of I'm too busy nowadays.I'm planning to focus to solve this issue on next weekend.
I'll inform about my success or not.
Hi Nazim,
suggest you try programming the micro to transmit an endless stream of 0x55 characters.
This will allow easy measurement of the micro baud rate and UART config on the 'scope. Assuming 8,N,1 you should see:
111111 etc - line idle high
0 - start bit
10101010 - 8 data bits, least significant bit first
111111 etc - stop bit plus line idle
Hi Stephen,
I did some work today and here are results,
I'm sending 1 byte from PC to micro:
PC(Trans) | Micro(Reciever)
------------- | -------------
0x03 | 0x83
0x04 | 0x84
0x0C | 0x8C
As shown above MSB bit is set in all recieves. And there isn't any framing or noise error on micro side.
Here is I'm sending 2 bytes from PC to micro:
PC(Trans) | Micro(Reciever)
------------- | -------------
0x05, 0x05 | 0x85, 0xE1
0x06, 0x06 | 0x86, 0xF8
0x01, 0x01 | 0x81, 0xE0
0x02, 0x02 | 0x82, 0xF0
After these results, I looked FT232R TXD pin with scope(0x05 is sending from PC side), In this picture FT232's TX pin is connected to micro's RX.
https://www.dropbox.com/s/hz7dteme55lo9wc/FTDI_TX_connected_micro_RX.png?dl=0
As seen in picture FT232 sends true value which is 0x05 but in micro side this value reading wrong.
Pulse width is 52usec. recieveBuffer[0] = 0x85
Then I connected micro's TX to micro's RX with same cables and I started sending 0x05 with 1sec time intervals.
Here is the result: https://www.dropbox.com/s/euisrlta707eoim/Micro_Tx_connected_Micro_RX.png?dl=0
Pulse width is 52usec.
I'm a bit confused :)
Hi Nazim,
based on the two waveforms and your measurements it looks as if the baud rates are set correctly at both ends.
It appears there may be a mismatch in the bits/char settings. The FTDI_TX waveform appears 'shorter', i.e. the right hand 0 is one division wide. The equivalent part of the Micro_Tx waveform is 1.25 divisions wide.
This suggests that the FTDI is set at 7 bits/char, no parity, 1 stop bit (7,N,1). Am guessing that the Micro is using 8,N,1. The micro is seeing the FTDI stop bit (1) as the MSB. This explains why 0x05 is received as 0x85.
Regarding the 2 byte results - a char size mismatch will cause the Micro receiver to be out of sync. A 2 byte send will transition from the stop bit bit to the next start bit immediately.
Assuming 7,N,1 the line will see:
11111 etc - idle
0 - char 1 start bit
1010000 - 0x05, 7 bits, LSB first
1 - char 1 stop bit
0 - char 2 stop bit
1010000 - 0x05, 7 bits, LSB first
1 - char 2 stop bit
11111 etc - idle
Micro see this as:
11111 - idle
1 - start bit (good)
10100001 - 0x85
0 - start bit 2 but expecting a stop bit, results in a framing error
1 - char 2 LSB, seen as line idle
0 - char 2 bit 1, seen as a start bit
10000111 - char 2 bits 2-6 plus stop plus idle, seen as 0xE1
1 - idle, seen as valid stop bit
11111 - idle
I suggest you set the Micro to 7,N,1 and retest. Thanks for the scope waveforms, they make debugging SO much easier.
Stm32f303vc isn't support 7bit word so I cant try it. I had yad2xxJava-0.3-SNAPSHOT jar file but I cant generate window dll file. Could you upload that file because I cant use setDataCharacteristics method, I'm getting "UnsatisfiedLinkError"(I'm using rev-0.2 dll).
I installed minGW(http://sourceforge.net/projects/mingw-w64/?source=typ_redirect), subversion 1.8.10 and maven 3.2.3. My java version is 1.7.0_67 then follow the steps in wiki but I'm getting an error while compiling window dll.
Here is the mvn install command output:
C:\Users\Nazım\workspaceFT>cd yad2xx
C:\Users\Nazım\workspaceFT\yad2xx>mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Yet Another JNI-D2XX Interface Library.
[INFO] yad2xx - Java Library
[INFO] yad2xx - Windows DLL
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Yet Another JNI-D2XX Interface Library. 0.3-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ yad2xx ---
[INFO] Installing C:\Users\Naz²m\workspaceFT\yad2xx\pom.xml to C:\Users\Naz²m.m
2\repository\net\sf\yad2xx\yad2xx\0.3-SNAPSHOT\yad2xx-0.3-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building yad2xx - Java Library 0.3-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ yad2xxJava
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Naz²m\workspaceFT\yad2xx\yad
2xxJava\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ yad2xxJava ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to C:\Users\Naz²m\workspaceFT\yad2xx\yad2xxJava\
target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ya
d2xxJava ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Naz²m\workspaceFT\yad2xx\yad
2xxJava\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ yad2xxJ
ava ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to C:\Users\Naz²m\workspaceFT\yad2xx\yad2xxJava\
target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ yad2xxJava ---
[INFO] Surefire report directory: C:\Users\Naz²m\workspaceFT\yad2xx\yad2xxJava\t
arget\surefire-reports
T E S T S
Running net.sf.yad2xx.FTDIBitModeTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.16 sec
Running net.sf.yad2xx.ModemStatusTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ yad2xxJava ---
[INFO] Building jar: C:\Users\Naz²m\workspaceFT\yad2xx\yad2xxJava\target\yad2xxJ
ava-0.3-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ yad2xxJava ---
[INFO] Installing C:\Users\Naz²m\workspaceFT\yad2xx\yad2xxJava\target\yad2xxJava
-0.3-SNAPSHOT.jar to C:\Users\Naz²m.m2\repository\net\sf\yad2xx\yad2xxJava\0.3-
SNAPSHOT\yad2xxJava-0.3-SNAPSHOT.jar
[INFO] Installing C:\Users\Naz²m\workspaceFT\yad2xx\yad2xxJava\pom.xml to C:\Use
rs\Naz²m.m2\repository\net\sf\yad2xx\yad2xxJava\0.3-SNAPSHOT\yad2xxJava-0.3-SNA
PSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building yad2xx - Windows DLL 0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for net.sf.yad2xx:yad2xxJava:jar:0.2-SNAPSHOT is missing, no d
ependency information available
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Yet Another JNI-D2XX Interface Library. ............ SUCCESS [ 1.187 s]
[INFO] yad2xx - Java Library .............................. SUCCESS [ 14.256 s]
[INFO] yad2xx - Windows DLL ............................... FAILURE [ 1.143 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.936 s
[INFO] Finished at: 2014-12-19T22:44:53+02:00
[INFO] Final Memory: 17M/179M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project FTDIInterface: Could not resolve depen
dencies for project net.sf.yad2xx:FTDIInterface:dll:0.2-SNAPSHOT: Could not find
artifact net.sf.yad2xx:yad2xxJava:jar:0.2-SNAPSHOT -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyReso
lutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :FTDIInterface
C:\Users\Nazım\workspaceFT\yad2xx></goals>
Last edit: NAZIM YILDIZ 2014-12-19
Hi Nazim,
see page 841 of the ST32f303x reference manual. The M1:0 bits in USARTx_CR1 control the number of bits, M[1:0] = 10: 1 Start bit, 7 data bits, n stop bits.
I intend to release a new library early January, when I return from holiday.
Cheers!
Hi Nazim,
happy new year.
I have been able to build a 64 bit Windows DLL but need to verify something. I have a Windows 8.1 x64 bit install but looks like I have 32 bit versions of IE and Chrome running. Could you please check your environment using the steps described here: https://www.java.com/en/download/faq/java_win64bit.xml please?
Thanks,
Stephen
Hi Stephen,
happy new year to you.
I'm using Win8.1 x64 but my chrome is 32bit(Version 39.0.2171.95 m).
What is the purpose of that information?
Have nice days.
Because the JVM bit size needs to be matched to the browser bit size e.g. 32 and the DLL bit size needs to match the JVM.
I was surprised to find out that I was using a 32 bit JVM on an x64 OS.