Gadget Renesas

Linking Ideas and Electronics

GR Atelier

Title:Let's try the function on GR-KURUMI, serial vol.

Displayed Name:@chobichan

Let's try the function on GR-KURUMI, serial vol.

Concept / Overview
Let's try the serial function on GR-KURUMI.

Let's try the serial function

Login in web compiler and generate new project or re-open the project which you just built last time. Let's practice.

GR-KURUMI CPU RL78/G13 has several hardware serials unlike Atmega32BP, in Arduino. GR-KURUMI support three serials, Serial, Serial1 and Serial2.





Please refer to the code below for how to use each hardware serial.

void setup()
  Serial.println("hello serial.");
  Serial1.println("hello serial1.");
  Serial2.println("hello serial2.");

The terminal number 0,1 on GR-KURUMI assigned for serial is used as the one for writing program, RXI, TXO. Can confirm output as it is on Tera Term after writing program into GR-KURUMI.


Serial1 is assigned to the terminal 7, 8.
Serial 2 to the terminal 9, 10.

both Serial1 and Serial2 are not connected to USB serial adaptor chip. If users would like to confirm output of Serial 1 and 2 in their PC, they have to connect some devices (wireless module etc.) on hardware.






Baud rate

In the case of Arduino Pro Mini, CPU Clock is 8MHz.

Actually, Arduino Pro Mini operate with baud rate up to 57,600bps.

CPU on GR-KURUMI works at 32MHz clock, so its baud rate is surely faster than Arduino Pro Mini.

Here is the code for GR-KURUMI.



void setup()
    while( Serial.available() == 0 ) ;


This program repeats “once receive, send it out.”
This program is called “loopback program”, useful to simply determine the normality/abnormality of the hardware devices on boards or cables.



On GR-KURUMI, you can set the faster baud rate than Arduino Pro Mini, without procedures such as flow control etc., some times the data will be missing while transmitting/receiving a large amount of data. 
This possible data missing phenomenon should be taken into consideration on data transmission though we can’t say what seems to be a problem. ※Flow control has two methods, by software or hardware. Without judging receiving buffer status,it wouldn’t be implemented. Wishing flow control would be supported by library side.







Holding hands in a ring

With three serials, let’s try unique operation check.

Please refer to the code below, pin layout on breadboard in the chart. Use jump wire or something for connecting No. 7 and 8, No. 9 and 10.





void setup()
    if( Serial.available() > 0 )

    if( Serial1.available() > 0 )

    if( Serial2.available() > 0 )

The data received from Serial is sent out to Serial1.
The data received by Serial 1 is sent out to Serial 2.

Finally, the data received by Serial 2 is sent back to Serial. “Loopback” through three serials.




Buffer size adjustment

On serial communication, sometimes MCU treat the data as packet.When MCU transmit and receive a packet data of several hundred bite, if the buffer on serial has enough capacity, MCU can read/write it at a time, it would be more efficient on programming. While Arduino Pro Mini has only 2k bite of SRAM for buffer, GR-KURUMI has 10 times as much as Arduino.

Even ten times of SRAM size, GR-KURUMI has only 64kbyte library for buffer size in line with Arduino.The serial on GR-KURUMI wouldn’t generate buffer automatically when it generates instance, is already secured as the time of booting. 
Please refer to「HardwareSerial.cpp」for the source code which influence buffer size.






Set the figure in the definition SERIAL_BUFFER_SIZE, you can adjust buffer size using for transmitting/ receiving the data.

Hmm..., if you change the figure in SERIAL_BUFFER_SIZE, everything (sending, receiving, serial, serial 1, serial 2) will change its size.
Everything is not necessary. If structure body ring_buffer consisted of buffer address, size, head and tail,it would solve problem by replacement with buffer and its size which was generated separately.

struct ring_buffer
  unsigned char *buffer;
  volatile unsigned int head;
  volatile unsigned int tail;
  volatile unsigned int size;

MVP information @chobichan

General hard engineer... occasinally writing for technical magazine.