Skip to content

Commit f646a97

Browse files
add better code for arduino uart helper
1 parent a936773 commit f646a97

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

gowin_empu/README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,22 +449,38 @@ Each C file gets a listing inside the Debug directory, for example the "main.c"
449449
}
450450
</details>
451451

452-
* Connect pin 19 of the Nano 4K to a USB-UART converter, and add a pull-up resistor (10k ish or so should be good) to the Vcc of the converter. We set the UART TX pin to open-drain configuration which means the pull-up is necessary to actually see any kind of signal, I'm using an Arduino Uno which has the ability to add internal 5V pull-up resistors. The Arduino sketch I used is provided here for reference (it's probably not the best implementation but it works).
452+
* Connect pin 19 of the Nano 4K to a USB-UART converter, and add a pull-up resistor (10k ish or so should be good) to the Vcc of the converter. We set the UART TX pin to open-drain configuration which means the pull-up is necessary to actually see any kind of signal, I'm using an Arduino Uno which has the ability to add internal 5V pull-up resistors.
453+
* * The Arduino sketch I used is provided here for reference (it's probably not the best implementation but it works, connect pin 19 of the Nano 4K to pin 7 of the Uno).
454+
453455
<details>
454456
<summary><b>Show code</b></summary>
455457

458+
#include <SoftwareSerial.h>
459+
460+
#define rxPin 7;
461+
#define txPin 6;
462+
463+
SoftwareSerial softUart (rxPin, txPin);
456464
457465
void setup() {
458-
Serial.begin(9600);
459-
pinMode(0, INPUT_PULLUP);
466+
Serial.begin(9600);
467+
softUart.begin(9600);
468+
pinMode(rxPin, INPUT_PULLUP);
460469
}
461-
462-
void loop() {}
463-
464-
void serialEvent() {
465-
while (Serial.available()) {
466-
Serial.print((char)Serial.read());
467-
}
470+
471+
void loop() {
472+
if (softUart.available()) {
473+
char c = mySerial.read();
474+
Serial.print(c);
475+
}
476+
if (Serial.available()) {
477+
char c = Serial.read();
478+
softUart.print(c);
479+
480+
//Gowin EMPU's UART isn't buffered, sending characters
481+
//too fast results in some of them being missed
482+
delay(1);
483+
}
468484
}
469485

470486
</details>
@@ -589,4 +605,4 @@ Relevant Gowin documentation:
589605
* [Gowin_EMPU IDE user guide (IPUG928E)](http://cdn.gowinsemi.com.cn/IPUG928E.pdf) for more information on the usage of J-Link debuggers, Keil MDK and more.
590606
* [Gowin_EMPU Software Design(IPUG931E)](http://cdn.gowinsemi.com.cn/IPUG931E.pdf) for the EMPU's memory map, peripheral register definition and more.
591607
* [Gowin_EMPU Hardware Design(IPUG932E)](http://cdn.gowinsemi.com.cn/IPUG932E.pdf) for signal definition, peripheral details and more.
592-
* [The latest version of GW1NS-4C example projects and libraries from Gowin](https://cdn.gowinsemi.com.cn/Gowin_EMPU(GW1NS-4C)_V1.1.3.zip). Make sure to alter SRAM and clock configurations to match your FPGA design setup.
608+
* [The latest version of GW1NS-4C example projects and libraries from Gowin](https://cdn.gowinsemi.com.cn/Gowin_EMPU(GW1NS-4C)_V1.1.3.zip). Make sure to alter SRAM and clock configurations to match your FPGA design setup.

0 commit comments

Comments
 (0)