Lesson 003: UART

Today we’ll be getting the UART module setup and running. It takes a bit of digging to figure out where the UART module is and how it’s hooked up.

The DK-S7G2 has three standard 12-pin Digilent Pmod connectors (Pmod B, C, and D). Unfortunately, these are also shared with the Bluetooth Low Energy Module (Pmod B), and SDRAM (Pmod C, Pmod D).

Pmod A is on the main board and isn’t shared with any other peripherals. This is the best choice for me to try something new. Following the User’s Manual for the DK-S7G2, I have set DIP switch 4, on S5 to the ON position.

Following Table 11: Pmod A connector (J5), I have also attached the TX, RX, and GND lines to a 3.3V FTDI serial breakout cable (https://www.sparkfun.com/products/9717).


Always remove power from the dev kit before attaching or removing anything, especially something with power on it!

Create a project as normal, check the r_sci_common and r_sci_uart checkbox on Components.

Add the SCI Command and UART Driver on r_sci_uart to the HAL/Common thread.

Change the Asynchronous Mode (r_sci_uart) to Enabled.

If you are using Synergy v1.1.0 or later, you will also need to remove the DTC Driver from the Transmission and Reception.

With the above steps complete, click on Generate Project Content.

Here’s the code for the main program.

/* HAL-only entry function */
#include "hal_data.h"
void hal_entry(void)
    // Create a simple message
    uint8_t data[] = "This is a test";
    // Catch the function call results for debugging
    ssp_err_t openResult;
    ssp_err_t writeResult;

    // Open the UART driver
    openResult = g_uart.p_api->open(g_uart.p_ctrl, g_uart.p_cfg);
    // Send the message data
    writeResult = g_uart.p_api->write(g_uart.p_ctrl, data, 14);

After opening a serial terminal and running the code…nothing happens. Grrrr…

OK, total PEKAC. Giong back to the DK-S7G2’s User Manual, under section 4.1 Pmod A, it says “Pmod A is connected to channel 8 of the SCI peripheral…”

Going back to the Synergy Configuration, under Threads > HAL/Common > g_uart UART Driver on r_sci_uart, the Module property has a Channel setting, which is defaulted to 0.

After changing this to 8 and running the code….IT WORKS!

I’ve used quite a few microcontrollers in the past (PIC24, PIC32, Atmel Cortex, and Arduino), and with the exception of the Arudino, I’ve never before had such an easy time setting up a peripheral for the first time. The Arduino is pretty straight forward as long as you use their library functions, but those functions are also not very customizable. The Synergy platform is easy to use (once you get used to how to setup the peripherals). The IDE is OK (nothing that I’ve used even comes close to Visual Studio), but it is certainly usable.

In about 6 hours spread over the last two weeks, I’ve gone from never using the Synergy platform to getting GPIO, Timers, and UART working. For me, this is pretty incredible.

Coming up in the near future:

Serial Port echo program (read and echo back characters)

Redirecting printf to the serial port

Using interrupts and rewriting previous days to an interrupt driven system

Analog To Digital

And More!


9 thoughts on “Lesson 003: UART

  1. Hi, Im actually new to the Synergy board and I tried out your example to familiarize with UART on S7G2-SK. Im taking the output from pin headers that break-out every pin on the S7G2 processor (411 for Tx, 410 for Rx) and am giving this output directly to my PC using a DB9 Female to DB9 Female RS232 Serial Cable. I am using channel 0, baud rate 9600 (default settings). Though the return value for write function is a success, I cannot see anything using Putty/ tera term. Any suggestions where I could me going wrong?


    1. NewOne,

      It you take a direct connection from your computer RS-232 cable, you will most likely damage your microcontroller!

      RS-232 uses a +/- 3V to 25V signal.

      The controller uses 0 to 3.3V. The SK does indeed have a RS-232 connection. This is J7 on your board. You should connect the following:

      Pin 2 of your RS-232 port to J7-4 (Computer RX)
      Pin 3 of your RS-232 port to J7-5 (Computer TX)
      Pin 5 of your RS-232 port to J7-6 (GND)

      The microcontroller TX pin is P7-07. The RX is P7-06.

      If you look at the schematic for the SK-S7G2, on page 7 you can see the RS232/485/CAN pinouts. At the bottom of the schematic shows the pins that connect to the microcontroller.

      The top of the schematic is the TTL (0-3.3V) to RS-232 converter (it uses capacitors C45 and C47 as a charge pump and generates +/- 6.6V

      You then need to configure your SCI Common channel to correspond to the correct pins (P7-06 and P7-07).

      Let me know if this helps!


  2. Also, if you want to use an FTDI 3.3V cable (see above link), then you can use any supported pin directly on the microcontroller. My examples use SCI8 and pins are set accordingly. This was due to the convenience of the header that SCI8 is connected to – it could be any SCI channel.


  3. What is the difference in using driver for UART and framework for UART? (Communications Framework on sf_uart_comms). I used the framework actually and transmission is successful, but the callback goes to callBack for the framework, not user defined callback for UART driver.


    1. I would have to look through the code, but I think the driver uses the framework behind the scenes.

      Try this yourself – step through you code on a UART read or Write and see which methods are called.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s