Gadget Renesas

Linking Ideas and Electronics

がじぇるね工房

Using function on GR-KURUMI, Serial vol.

GR-KURUMIの機能を使う アナログ入力(ADC)編

####

Let’s try hardware serial

image01 image02

GR-KURUMI CPU RL78/G13 has several hardware serials unlike Atmega32BP, in Arduino. GR-KURUMI support three serials (Serial, Serial1, Serial2). Let’s try to generate new project on web compiler or re-open project if you have built already.

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

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.

image03

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

image04

CPU Clock works at 8MHz on Arduino Pro Mini.In actual measurement, Arduino Pro Mini operate with baud rate up to 57,600bps.
CPU works at 32MHz clock on GR-KURUMI, expecting its baud rate is faster than Arduino Pro Mini.Here is the code for GR-KURUMI.

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.

image05

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

image06 image07

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.

image08

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.

image09

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

I can’t believe.

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.

https://dl.dropboxusercontent.com/u/60463387/grkurumi/hardwearSerial/HardwareSerial.cpp

MVP information

@chobichan

General hard engineer.. submitting his writing for technical magazine occasionally.
twitter account:
https://twitter.com/chobichan

Chobichan avatar

Follow him

All articles from @chobichan

share