Renesas RJJ10J1643-0101 User Manual

To our customers,
Old Company Name in Catalogs and Other Documents
On April 1st, 2010, NEC Electronics Corporation merged with Renesas Technology Corporation, and Renesas Electronics Corporation took over all the business of both companies. Therefore, although the old company name remains in this document, it is a valid Renesas Electronics document. We appreciate your understanding.
Renesas Electronics website: http://www.renesas.com
April 1 Renesas Electronics Corporation
Issued by: Renesas Electronics Corporation (http://www.renesas.com)
st
, 2010
Send any inquiries to http://www.renesas.com/inquiry
.
Notice
1. All information included in this document is current as of the date this document is issued. Such information, however, is
subject to change without any prior notice. Before purchasing or using any Renesas Electronics products listed herein, please confirm the latest product information with a Renesas Electronics sales office. Also, please pay regular and careful attention to additional and different information to be disclosed by Renesas Electronics such as that disclosed through our website.
2. Renesas Electronics does not assume any liability for infringement of patents, copyrights, or other intellectual property rights
of third parties by or arising from the use of Renesas Electronics products or technical information described in this document. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas Electronics or others.
3. You should not alter, modify, copy, or otherwise misappropriate any Renesas Electronics product, whether in whole or in part.
4. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of
semiconductor products and application examples. You are fully responsible for the incorporation of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits, software, or information.
5. When exporting the products or technology described in this document, you should comply with the applicable export control
laws and regulations and follow the procedures required by such laws and regulations. You should not use Renesas Electronics products or the technology described in this document for any purpose relating to military applications or use by the military, including but not limited to the development of weapons of mass destruction. Renesas Electronics products and technology may not be used for or incorporated into any products or systems whose manufacture, use, or sale is prohibited under any applicable domestic or foreign laws or regulations.
6. Renesas Electronics has used reasonable care in preparing the information included in this document, but Renesas Electronics
does not warrant that such informatio n is error free. Renesas Electronics assumes no liability whatsoever for any damages incurred by you resulting from errors in or omissions from the information included herein.
7. Renesas Electronics products are classified according to the following three quality grades: “Standard”, “High Quality”, and
“Specific”. The recommended applications for each Renesas Electronics product depends on the product’s quality grade, as indicated below. You must check the quality grade of each Renesas Electronics product before using it in a particular application. You may not use any Renesas Electronics product for any application categorized as “Specific” without the prior written consent of Renesas Electronics. Further, you may not use any Renesas Electronics product for any application for which it is not intended without the prior written consent of Renesas Electronics. Renesas Electronics shall not be in any way liable for any damages or losses incurred by you or third parties arising from the use of any Renesas Electronics product for an application categorized as “Specific” or for which the product is not intended where you have failed to obtain the prior written consent of Renesas Electronics. The quality grade of each Renesas Electronics product is “Standard” unless otherwise expressly specified in a Ren esas E lectronics data sheets or dat a books, etc.
“Standard”: Computers; office equipment; communications equipment; test and measurement equipment; audio and visual
equipment; home electron ic appliances; machine tools; personal electronic equipment; and industrial robots.
“High Quality”: Transportation equipment (automobiles, trains, ships, etc.); traffic control systems; anti-disaster systems; anti-
crime systems; safety equipment; and medical equipment not specifically designed for life support.
“Specific”: Aircraft; aerospace equipment; submersible repeaters; nuclear reactor control systems; medical equipment or
systems for life support (e.g. artificial life support devices or systems), surgical implantations, or healthcare intervention (e.g. excision, etc.), and any other appl i cations or purposes that pose a d irect threat to human life.
8. You should use the Renesas Electronics products described in this document within the range specified by Renesas Electronics,
especially with respect to the maximum rating, operating supply voltage range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas Electronics shall have no liability for malfunctions or damages arising out of the use of Renesas Electronics products beyond such specified ranges.
9. Although Renesas Electronics endeavors to improve the quality and reliability of its products, semiconductor products have
specific characteristics such as t he occu rrence o f failure at a certai n rate an d malfunct io ns under cert ain u se con dition s. Further, Renesas Electronics prod ucts are not subject to radiation resistance design. Please be sure to implement safety measures to guard them against the possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas Electronics product, such as safety design for hardware and software including but not limited to redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures. Because the evaluation of microcomputer software alone is very difficult, please evaluate the safety of the final products or system manufactured by you.
10. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental
compatibility of each Renesas Electronics product. Please use Renesas Electronics products in compliance with all applicable laws and regulations that regulate the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive. Renesas Electronics assumes no liability for damages or losses occurring as a result of your noncompliance with applicable laws and regulations.
11. This document may not be reproduced or duplicated, in any form, in whole or in part, without prior written consent of Renesas
Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this
document or Renesas Electronics products, or if you have any other inquiries.
(Note 1) “Renesas Electronics” as used in this document means Renesas Electronics Corporation an d also includes its majority-
owned subsidiaries.
(Note 2) “Renesas Electronics product(s)” means any product developed or manufactured by or for Renesas Electronics.
User’s Manual
Renesas Embedded Application Programming Interface
Reference manual
Rev.1.01 2007.02
REVISION HISTORY Rev.
1.00 06.04.07
1.01 Additions and corrections made for support of libraries for the H8/36094, H8/36077, H8/36109, and R8C/24 and 25
Unnecessary periods in Chapter 1, “Instruction,” deleted Port P73 of H8 deleted Channels A–D written in CreateInputCapture corrected to input captures A–D
Error in writing “seroal” corrected to “serial”
Erroneous description of RAPI_70_STATES corrected
Error in writing of timer channel names corrected
Error in writing of input capture mode corrected
Error in writing of output compare mode corrected
Erroneous description of RAPI_OVERFLOW_BIT15 corrected
Support for R8C UART1 clock synchronous mode
RAPI_COUNT_CLEAR added to first arguments for the R8C and H8/300H in
__CreateInputCapture and __CreateOutputCompare
“External signal” deleted from the timer RD count source for the R8C in
__CreateInputCapture and __CreateOutputCompare
Following statements added to the item for timer RD in __SetTimerRegister and
__GetTimerRegister
[15]: Timer RD output master enable register 1
[16]: Timer RD output master enable register 2
[17]: Timer RD output control register
Explanation for clearing H8/300H module added to the description of __Create...,
__Open..., and __BasicOpen...
Explanation for setting H8/300H module for standby added to the description of
__Destroy..., __Close..., and BasicClose...
Return value in __PollingSerialReceiving changed from Boolean to unsigned int, and
explanation of return value and example program changed
Return value in __PollingSerialSending changed from Boolean to unsigned int, and
explanation of return value and example program changed
Remarks regarding use of port B on H8/300H added to __ReadIOPort and
__ReadIOPortRegister
Summary
Date
07.02.16
Rev.1.01 2007.02.16 RJJ10J1643-0101
2
Description of third argument in __CreateInputCapture corrected
Wording “specified” unified to “specified”
RAPI_BOTH deleted from the description of timer B1 count edges of H8/300H in
__CreateEventCounter
RAPI_FTIOA and RAPI_FTIOB added to __CreatePulsePeriodMeasurementMode and
__CreatePulseWidthMeasurementMode
All occurrences of the word “Tiny” deleted
Description of second argument added to __GetPulsePeriodMeasurementMode,
__GetPulseWidthMeasurementMode, and __GetEventCounter
Description regarding timer V trigger of H8 in __CreateTimer, __CreateEventCounter,
and __CreatePulseWidthMeasurementMode corrected
Explanation of H8 interrupt settings and interrupt control register settings in
__SetSerialInterrupt corrected
Remarks on timer V of H8/300H in __EnableTimerRegister added
Specification of timer RA input pins of R8C in __CreatePulsePeriodMeasurementMode
and __CreatePulseWidthMeasurementMode as well as RAPI_TIOSEL_P1_7 and
RAPI_TIOSEL_P1_5 added
File name in program example corrected
Item “Reference” in __BasicSetSerialFormat deleted
__BasicSetSerialFormat added to “Reference” in __SetSerialFormat and
__SetSerialInterrupt
Error in writing of __CreateInput Capture and __CreateOutputCapture corrected
Explanation added to Section 2.1, “Overview”
Causes of clearing of timer W and timer RC counters in __CreateInputCapture deleted
RAPI_COMPARE_MATCH_A_STOP and RAPI_STOP added to the item for the R8C in
__CreateOutputCompare
Changed to RAPI_INT_LV_0 and RAPI_INT_LV_1 for H8/300H in __SetSerialInterrupt
Description relating to clock in __CreateTimer corrected
RAPI_TRC_FILTER and RAPI_TRD_FILTER added to filter specification for H8 in
__CreatePulsePeriodMeasurementMode and __CreatePulseWidthMeasurementMode
RAPI_TIMER_RD2 and RAPI_TIMER_RD3 added to timer RD of H8/36109
Description relating to timer V trigger input for H8/300H in __CreateTimer deleted
Description of pulse output function added to the item for R8C in
__CreateEventCounter
Description of timer RE usage added to items data3 and data5 for R8C in
__CreateOutputCompare
Filter function of timer RC and timer RD in __CreatePulsePeriodMeasurementMode,
__CreatePulseWidthMeasurementMode, and __CreateInputCapture corrected
Description that multiple defined values can be set for data1 in __EnableInterrupt
added
Description that RAPI_WITHOUT_SAMPLE_HOLD is specifiable in delay trigger
modes 0 and 1 of M16C in __CreateADC corrected
Description that RAPI_FOCOF is specifiable in repeat mode of R8C in __CreateADC
corrected
Rev.1.01 2007.02.16 RJJ10J1643-0101
3
RAPI_AN30, RAPI_AN31, RAPI_AN32, and RAPI_P9_GROUP added to the item for
data1 of M16C in __CreateADC
RAPI_AN30, RAPI_AN31, RAPI_AN32, and RAPI_P9_GROUP added to the item for
data1 of M16C in __EnableADC
Error in writing of H8/300H interrupt set values in __CreateOutputCompare corrected
Error in writing of timer RD and timer RD symbol name corrected
Description of gate function of M16C in __CreateEventCounter deleted
Description of H8/300H noise rejection function in __BasicSetSerialFormat added
Description of timer W input pins of H8/300H in
__CreatePulsePeriodMeasurementMode and __CreatePulseWidthMeasurementMode
deleted
Rev.1.01 2007.02.16 RJJ10J1643-0101
4
Table of Contents
Table of Contents ................................................................5
1. Introduction................................................................... 8
2. Driver ....................................................................... 9
2.1 Overview.................................................................. 9
2.2 Driver Features ............................................................ 10
2.3 Serial Interface Driver....................................................... 11
2.4 Timer Driver .............................................................. 12
2.4.1 Timer Mode ........................................................... 12
2.4.2 Event Counter Mode .................................................... 12
2.4.3 Pulse Width Modulation Mode (PWM Mode)................................. 12
2.4.4 Pulse Period Measurement Mode .......................................... 12
2.4.5 Pulse Width Measurement Mode........................................... 12
2.4.6 Input Capture Mode..................................................... 12
2.4.7 Output Compare Mode .................................................. 13
2.5 I/O Port Driver ............................................................ 14
2.6 External Interrupt Driver..................................................... 15
2.7 A/D Converter Driver ....................................................... 16
3. Standard Types ............................................................... 18
4. Library Reference............................................................. 19
4.1 API List by Peripheral Facility ................................................ 19
4.2 Description of Each API ..................................................... 21
4.2.1 Serial I/O ............................................................. 22
__BasicOpenSerialDriver................................................... 22
__BasicCloseSerialDriver................................................... 23
__BasicSetSerialFormat .................................................... 24
__BasicStartSerialReceiving................................................. 29
__BasicStartSerialSending .................................................. 30
__BasicReceivingStatusRead ................................................ 31
__BasicSendingStatusRead.................................................. 33
__BasicStopSerialReceiving................................................. 34
__BasicStopSerialSending .................................................. 35
__OpenSerialDriver ....................................................... 36
__CloseSerialDriver ....................................................... 37
__ConfigSerialDriverNotify................................................. 38
__SetSerialFormat......................................................... 41
__SetSerialInterrupt ....................................................... 42
__StartSerialReceiving ..................................................... 45
__StartSerialSending....................................................... 47
__StopSerialReceiving ..................................................... 49
__StopSerialSending....................................................... 50
__PollingSerialReceiving ................................................... 51
__PollingSerialSending..................................................... 52
4.2.2 Timer ................................................................54
Rev.1.01 2007.02.16 RJJ10J1643-0101
5
__CreateTimer ........................................................... 54
__EnableTimer ........................................................... 60
__DestroyTimer .......................................................... 62
__CreateEventCounter ..................................................... 64
__EnableEventCounter..................................................... 69
__DestroyEventCounter .................................................... 71
__GetEventCounter........................................................ 73
__CreatePulseWidthModulationMode ......................................... 75
__EnablePulseWidthModulationMode......................................... 80
__DestroyPulseWidthModulationMode ........................................ 82
__CreatePulsePeriodMeasurementMode ....................................... 83
__EnablePulsePeriodMeasurementMode ....................................... 88
__DestroyPulsePeriodMeasurementMode ...................................... 90
__GetPulsePeriodMeasurementMode.......................................... 92
__CreatePulseWidthMeasurementMode........................................ 94
__EnablePulseWidthMeasurementMode ....................................... 99
__DestroyPulseWidthMeasurementMode ..................................... 101
__GetPulseWidthMeasurementMode ......................................... 103
__CreateInputCapture..................................................... 105
__EnableInputCapture .................................................... 115
__DestroyInputCapture.................................................... 117
__GetInputCapture ....................................................... 119
__CreateOutputCompare .................................................. 121
__EnableOutputCompare .................................................. 133
__DestroyOutputCompare ................................................. 135
__SetTimerRegister ...................................................... 137
__EnableTimerRegister.................................................... 143
__ClearTimerRegister..................................................... 145
__GetTimerRegister ...................................................... 147
4.2.3 I/O Port ............................................................. 153
__SetIOPort ............................................................ 153
__ReadIOPort ........................................................... 158
__WriteIOPort........................................................... 162
__SetIOPortRegister...................................................... 166
__ReadIOPortRegister .................................................... 168
__WriteIOPortRegister.................................................... 170
4.2.4 External interrupt...................................................... 172
__SetInterrupt ........................................................... 172
__EnableInterrupt ........................................................ 176
__GetInterruptFlag ....................................................... 178
__ClearInterruptFlag...................................................... 180
4.2.5 A/D converter......................................................... 182
__CreateADC ........................................................... 182
__EnableADC........................................................... 191
__DestroyADC .......................................................... 196
Rev.1.01 2007.02.16 RJJ10J1643-0101
6
__GetADC ............................................................. 197
__GetADCAll........................................................... 198
__GetADCStatus......................................................... 199
__ClearADCStatus ....................................................... 200
Rev.1.01 2007.02.16 RJJ10J1643-0101
7
1. Introduction
The Renesas Embedded Application Programming Interface (API) is a unified API for
the microcomputers made by Renesas Technology Corporation.
Rev.1.01 2007.02.16 RJJ10J1643-0101
8
2. Driver
2.1 Overview
The library described herein provides a peripheral facility control program (peripheral driver) for microcomputers. Use of the Renesas API permits the peripheral driver to be built into a user program.
Configuration of Renesas APIs is shown below.
File name Description
rapi_
xxx_yyy
(
xxx
= family name,
rapi_ad_
xxx
= family name,
(
rapi_io_port_
xxx
= family name,
(
rapi_sif_
xxx
= family name,
(
rapi_timer_
xxx
= family name,
(
Interrupt_ (
xxx
= family name,
rapi_io_
xxx
= family name,
(
.lib
xxx_yyy
xxx_yyy
xxx_yyy
xxx_yyy
xxx_yyy
xxx_yyy
.h
.h
.h
yyy
= series name)
yyy
= series name)
.h
yyy
= series name)
yyy
= series name)
.h
yyy
= series name)
.h
yyy
= series name)
yyy
= series name)
This is the Renesas API library file. To use Renesas APIs, specify this file as input file for the linker. This is the header file for A/D converter driver APIs. To use A/D converter driver APIs, be sure to include this file. This is the header file for I/O port driver APIs. To use I/O port driver APIs, be sure to include this file. This is the header file for serial I/F driver APIs. To use serial I/F driver APIs, be sure to include this file. This is the header file for timer driver APIs. To use timer driver APIs, be sure to include this file. This is the interrupt function source file for Renesas APIs. To use Renesas APIs that use interrupts, add this file to the user program. This is the CPU control register definition header file for Renesas APIs.
Rev.1.01 2007.02.16 RJJ10J1643-0101
9
2.2 Driver Features
The library described herein has the following features available as a peripheral driver.
(1) Serial I/O control feature
It comprises a serial interface driver, which sets or clears the conditions of serial
communication, as well as controls and manages the transmission/reception of
communication data.
(2) Timer control feature
It comprises a timer driver, which sets or clears the operating conditions of timers,
as well as controls the timer operation.
(3) I/O port control feature
It comprises an I/O port driver, which sets or clears the usage conditions of I/O ports, as
well as control data read/write operation.
(4) External interrupt control feature
It comprises an external interrupt driver, which sets or clears the usage conditions of
external interrupts, as well as controls interrupt operation.
(5) A/D converter control feature
It comprises an A/D converter driver, which sets or clears the usage conditions of A/D
converters, as well as controls A/D converter operation.
Rev.1.01 2007.02.16 RJJ10J1643-0101
10
2.3 Serial Interface Driver
The serial interface driver sets serial communication, clears settings, transmit/receives data, and controls the status of serial communication.
There are two kinds of serial interface driver: a single-data transmission/reception API
and a multi-data transmission/reception API.
Rev.1.01 2007.02.16 RJJ10J1643-0101
11
2.4 Timer Driver
The timer driver sets the timer, clears timer settings, controls timer operation, and acquires a counter value with respect to the following modes:
Timer mode
Event counter mode
Pulse width modulation mode (PWM mode)
Pulse period measurement mode
Pulse width measurement mode
Input capture mode
Output compare mode
2.4.1 Timer Mode
In this mode, the timer counts the internally generated count source. When an
underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.2 Event Counter Mode
In this mode, the timer counts the external signal fed in from an input pin or an overflow or underflow from other timer. When an underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.3 Pulse Width Modulation Mode (PWM Mode)
In this mode, the timer outputs pulses in a given width successively. When an underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.4 Pulse Period Measurement Mode
In this mode, the timer measures the pulse period of an external signal fed in from an input pin. When an underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.5 Pulse Width Measurement Mode
In this mode, the timer measures the pulse width of an external signal fed in from an input pin. When an underflow or an overflow interrupt occurs, it calls a preset callback function.
2.4.6 Input Capture Mode
In this mode, the timer latches the timer value upon an active signal edge or clock pulse at an input pin, thereby generating an interrupt request. When an input capture interrupt or an underflow or an overflow interrupt occurs, it calls a preset callback function.
Rev.1.01 2007.02.16 RJJ10J1643-0101
12
2.4.7 Output Compare Mode
In this mode, the timer generates an interrupt request when the timer counter and a comparison value match. When a compare match interrupt or an underflow or an overflow interrupt occurs, it calls a preset callback function.
Rev.1.01 2007.02.16 RJJ10J1643-0101
13
2.5 I/O Port Driver
The I/O port driver sets the I/O port for input or output, writes data to the I/O port, and
reads data from the I/O port.
Rev.1.01 2007.02.16 RJJ10J1643-0101
14
2.6 External Interrupt Driver
The external interrupt driver sets external interrupts, controls external interrupts,
acquires the status of external interrupt flags, and clears external interrupt flags.
Rev.1.01 2007.02.16 RJJ10J1643-0101
15
2.7 A/D Converter Driver
_
_
_
_
_
The A/D converter driver sets the A/D converter, controls the A/D converter, clears
settings of the A/D converter, acquires the A/D converter value, acquires the status of the A/D converter, and clears the status of the A/D converter.
[A/D converter driver usage example (single-shot mode)]
Here, a program example is shown for the A/D converter operating in single-shot mode
under the conditions given below.
CPU : R8C Operating clock : fAD divided by 2 Resolution : 10 bits Analog input pin : AN0 pin A/D conversion start condition : Software trigger Sample-and-hold : Enabled
A program flow and a program example are shown below.
(Program flow)
main()
Set the A/D converter in
single-shot mode
Start A/D conversion
No
A/D interrupt?
Yes
Read out the A/D conversion value
Clear the A/D interrupt flag
_CreateADC()
_EnableADC()
_GetADCStatus()
_GetADC()
_ClearADCStatus()
Rev.1.01 2007.02.16
16
RJJ10J1643-0101
__
Program example
#include "rapi_ad_r8c_13.h"
void main( void ) { unsigned int status, data;
/* Set up A/D converter as one short mode */
RAPI_WITH_SAMPLE_HOLD| RAPI_AD_OFF|RAPI_10BIT, 1, 0, 0 );
while( 1 ){ /* Disable A/D converter */ __EnableADC( RAPI_AN0| RAPI_AD_ON, 1 );
/* Check a flag bit of A/D converter interrupt */ do{ __GetADCStatus( &status ); } while( (*status & 0x0001) == 0 )
/* Get A/D convertered datas of A/D register */ __GetADC( &data );
/* Clear status of A/D convertered */ __ClearADCStatus( 0 ); } }
CreateADC( RAPI_ONE_SHOT|RAPI_AN0|RAPI_FAD2|
Rev.1.01 2007.02.16 RJJ10J1643-0101
17
3. Standard Types
This section describes the standard types defined in the library. For details about the
set values, refer to the description of each API.
Standard type Description
Boolean
Voi dF unc No ti fy
The Boolean type represents the enum-type data that indicates whether successful (RAPI_TRUE (= 1)) or failed (RAPI_FALSE (=
0)).
The VoidFuncNotify type represents the type of the notification function to be registered.
Rev.1.01 2007.02.16 RJJ10J1643-0101
18
4. Library Reference
4.1 API List by Peripheral Facility
The table below lists the Renesas Embedded APIs classified by peripheral facility.
NO Facility
classification
Single-data
1 __BasicOpenSerialDriver
serial I/O
2 __BasicCloseSerialDriver
3 __BasicSetSerialFormat
4 __BasicStartSerialReceiving
5 __BasicStartSerialSending
6 __BasicReceivingStatusRead
7 __BasicSendingStatusRead
8 __BasicStopSerialReceiving
9
Multi-data
10 __OpenSerialDriver
serial I/O
11 __CloseSerialDriver
12 __ConfigSerialDriverNotify
13 __SetSerialFormat
14 __SetSerialInterrupt
15 __StartSerialReceiving
16 __StartSerialSending
17 __StopSerialReceiving
18 __StopSerialSending
19 __PollingSerialReceiving
20
Timer
21 __CreateTimer
22 __EnableTimer
23 __DestroyTimer
24 __CreateEventCounter
25 __EnableEventCounter
26 __DestroyEventCounter
27 __GetEventCounter
28 __CreatePulseWidthModulationMode
29 __EnablePulseWidthModulationMode
30 __DestroyPulseWidthModulationMode
31 __CreatePulsePeriodMeasurementMode
32 __EnablePulsePeriodMeasurementMode
33 __DestroyPulsePeriodMeasurementMode
34
__BasicStopSerialSending
__PollingSerialSending
__GetPulsePeriodMeasurementMode
API API operation
Opens serial port
Closes serial port
Sets serial communication
Receives 1 data
Transmits 1 data
Reads receive status
Reads transmit status
Stops reception
Stops transmission
Opens serial port
Closes serial port
Registers notification function
Sets serial communication
Sets transmit/receive interrupt
Starts reception
Starts transmission
Stops reception
Stops transmission
Receives by polling
Transmits by polling
Sets timer mode
Controls timer mode operation
Clears timer mode setting
Sets event counter mode
Controls operation of event counter mode Clears setting of event counter mode Gets event counter mode counter value Sets pulse width modulation mode
Controls operation of pulse width modulation mode Clears setting of pulse width modulation mode Sets pulse period measurement mode Controls operation of pulse period measurement mode Clears setting of pulse width measurement mode Acquires measured value of pulse period measurement mode
Rev.1.01 2007.02.16 RJJ10J1643-0101
19
35 __CreatePulseWidthMeasurementMode
36 __EnablePulseWidthMeasurementMode
Timer
37 __DestroyPulseWidthMeasurementMode
38 __GetPulseWidthMeasurementMode
39 __CreateInputCapture
40 __EnableInputCapture
41 __DestroyInputCapture
42 __GetInputCapture
43 __CreateOutputCompare
44 __EnableOutputCompare
45 __DestroyOutputCompare
46 __SetTimerRegister
47 __EnableTimerRegister
48 __ClearTimerRegister
49
I/O port
50 __SetIOPort
51 __ReadIOPort
52 __WriteIOPort
53 __SetIOPortRegister
54 __ReadIOPortRegister
55
External
56 __SetInterrupt
interrupt
57 __EnableInterrupt
58 __GetInterruptFlag
59
A/D converter
60 __CreateADC
61 __EnableADC
62 __DestroyADC
63 __GetADC
64 __GetADCAll
65 __GetADCStatus
66
__GetTimerRegister
__WriteIOPortRegister
__ClearInterruptFlag
__ClearADCStatus Clears status of A/D converter
Sets pulse width measurement mode Controls operation of pulse width measurement mode Clears setting of pulse width measurement mode Acquires measured value of pulse width measurement mode Sets input capture mode
Controls operation of input capture mode Clears setting of input capture mode
Acquires counter value of input capture mode Sets output compare mode
Controls operation of output compare mode Clears setting of output compare mode Sets timer register
Controls operation of timer register
Clears timer register
Gets timer register value
Sets I/O port
Reads from I/O port
Writes to I/O port
Sets I/O port register
Reads from I/O port register
Writes to I/O port register
Sets external interrupt
Controls external interrupt
Gets flag status of external interrupt
Clears flag of external interrupt
Sets A/D converter
Controls operation of A/D converter
Discards settings of A/D converter
Gets A/D conversion value (register specified) Gets A/D conversion value (all registers) Gets status of A/D converter
Rev.1.01 2007.02.16 RJJ10J1643-0101
20
4.2 Description of Each API
This section describes each API and explains how to use them, showing a program
example for each.
The description of each API is divided into the following items.
• Synopsis
• Description
• Return value
• Functionality
• Reference
• Remark
• Program example
: Outlines the content of processing performed by the function. It
also shows the syntax of the function, followed by a brief explanation of arguments.
: Describes the function and how to use it in detail.
: Explains the returned value of the function.
: Indicates the functional classification of the function.
: Indicates the related functions.
: Describes the precautions to be taken when using the API.
: Presents a program showing how to use the function.
Rev.1.01 2007.02.16 RJJ10J1643-0101
21
4.2.1 Serial I/O __BasicOpenSerialDriver
Synopsis
Description
For data, the following values can be set.
(M16C)
(R8C)
(H8/300H)
Return value
Functionality
Reference
Remark
<Open a serial port>
Boolean __BasicOpenSerialDriver(unsigned long data)
data Setup data
Opens and initializes a specified serial port.
RAPI_COM1 UART0 RAPI_COM2 UART1
RAPI_COM3 UART2 RAPI_COM4 SI/O3
RAPI_COM5 SI/O4
RAPI_COM1 UART0 RAPI_COM2 UART1
RAPI_COM1 SCI3 channel 1 RAPI_COM2 SCI3 channel 2
RAPI_COM3 SCI3 channel 3
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
Serial I/O
__BasicCloseSerialDriver
The specifiable serial ports differ with each CPU used.
If an undefined value is specified in the argument, operation of the API cannot be
guaranteed.
When used for the H8/300H, this API opens and initializes a specified serial port
when freeing it from module standby state.
Program example
#include ”rapi_sif_r8c_13.h”
void func( void ) { /* Open serial driver */ return __BasicOpenSerialDriver( RAPI_COM1 ); }
Rev.1.01 2007.02.16 RJJ10J1643-0101
22
__BasicCloseSerialDriver
Synopsis
Description
(R8C)
(H8/300H)
<Close a serial port>
Boolean __BasicCloseSerialDriver(unsigned long data)
data Setup data
Closes a specified serial port. For data, the following values can be set.
(M16C)
RAPI_COM1 UART0 RAPI_COM2 UART1
RAPI_COM3 UART2 RAPI_COM4 SI/O3
RAPI_COM5 SI/O4
RAPI_COM1 UART0 RAPI_COM2 UART1
RAPI_COM1 SCI3 channel 1 RAPI_COM2 SCI3 channel 2
RAPI_COM3 SCI3 channel 3
Return value
Functionality
Reference
If the serial port specification is incorrect, RAPI_FALSE is returned; otherwise,
RAPI_TRUE is returned.
Serial I/O
__BasicOpenSerialDriver
The specifiable serial ports differ with each CPU used.
Remark
If an undefined value is specified in the argument, operation of the API cannot be
guaranteed.
When used for the H8/300H, this API places a specified serial port into module
standby state after closing it.
Program example
#include ”rapi_sif_r8c_13.h”
void func( void ) { /* Close serial driver */ return Rapi_BasicCloseSerialDriver( RAPI_COM1 ); }
Rev.1.01 2007.02.16 RJJ10J1643-0101
23
__BasicSetSerialFormat
Synopsis
Description
<Set serial communication>
Boolean __BasicSetSerialFormat(unsigned long data1, unsigned char data2)
data1 Setup data 1
data2 Setup data 2
Sets serial communication according to specified parameters.
[data1]
For data1, the following values can be set. To set multiple definition values at the same
time, use the symbol “|” to separate each specified value.
(M16C)
RAPI_COM1 UART0 RAPI_COM2 UART1
RAPI_COM3 UART2 RAPI_COM4 SI/O3
RAPI_COM5 SI/O4
For serial communication mode, the following values can be set.
(M16C) (UART0, UART1, UART2)
RAPI_SM_SYNC
RAPI_SM_ASYNC
(M16C)(SI/O3, SI/O4)
RAPI_SIO_SM_SYNC
For the data length format of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(M16C) (UART0, UART1, UART2)
RAPI_BIT_7 Transfer data length 7 bits RAPI_BIT_8 Transfer data length 8 bits
RAPI_BIT_9 Transfer data length 9 bits
For the clock source of serial communication, the following values can be set.
(M16C) (UART0, UART1, UART2)
RAPI_CKDIR_INT Internal clock is used as the clock source of serial communication.
RAPI_CKDIR_EXT External clock is used as the clock source of serial communication.
(M16C) (SI/O3, SI/O4)
RAPI_SIO_CKDIR_INT Internal clock is used as the clock source of serial communication.
RAPI_SIO_CKDIR_EXT External clock is used as the clock source of serial communication.
For the stop bit length of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(M16C) (UART0, UART1, UART2)
RAPI_STPB_1 1 stop bit RAPI_STPB_2 2 stop bits
For the parity bit of clock asynchronous serial communication, the following values can
be set.
Clock synchronous serial communication mode
Clock asynchronous serial communication mode
Clock synchronous serial communication mode
Rev.1.01 2007.02.16 RJJ10J1643-0101
24
If the API is used in clock synchronous serial communication mode, do not set these
values.
(M16C) (UART0, UART1, UART2)
RAPI_PARITY_NON No parity bit RAPI_PARITY_EVEN Even parity bit
RAPI_PARITY_ODD Odd parity bit
For the clock polarity of serial communication, the following values can be set.
If the API is used in clock asynchronous serial communication mode, do not set these
values.
(M16C) (UART0, UART1, UART2)
RAPI_DPOL_NON Polarity not inverted RAPI_DPOL_INV Polarity inverted
(M16C) (SI/O3, SI/O4)
RAPI_SIO_DPOL_NON Polarity not inverted RAPI_SIO_DPOL_INV Polarity inverted
For the count source of the built-in baud rate generator, the following values can be set.
(M16C) (UART0, UART1, UART2)
RAPI_BCSS_F1 f1SIO RAPI_BCSS_F2 f2SIO
RAPI_BCSS_F8 f8SIO RAPI_BCSS_F32 f32SIO
(M16C) (SI/O3, SI/O4)
RAPI_SIO_BCSS_F1 f1SIO RAPI_SIO_BCSS_F2 f2SIO
RAPI_SIO_BCSS_F8 f8SIO RAPI_SIO_BCSS_F32 f32SIO
For the _CTS/_RTS function, the following values can be set.
If the internal clock is selected for use in clock synchronous serial communication
mode, the _RTS function has no effect.
(M16C) (UART0, UART1, UART2)
RAPI_CTSRTS_DIS _CTS/_RTS functions are not used.
RAPI_CTS_SEL _CTS function is selected.
RAPI_RTS_SEL _RTS function is selected.
For the transfer format, the following values can be set.
If the data length selected for use in clock asynchronous serial communication mode is
7 or 9 bits long, do not set these values.
(M16C) (UART0, UART1, UART2)
RAPI_LSB_SEL LSB first RAPI_MSB_SEL MSB first
(M16C) (SI/O3, SI/O4)
RAPI_SIO_LSB_SEL LSB first RAPI_SIO_MSB_SEL MSB first
For serial data logic switchover, the following values can be set.
(M16C) (UART2)
RAPI_LOGIC_NO_REV
RAPI_LOGIC_REV The value written in the transmit buffer register is inverted before
(R8C)
RAPI_COM1 UART0 RAPI_COM2 UART1
For serial communication mode, the following values can be set.
The value written in the transmit buffer register does not have its
logic inverted.
being transmitted.
Rev.1.01 2007.02.16 RJJ10J1643-0101
25
(R8C) (UART0, UART1)
RAPI_SM_SYNC
RAPI_SM_ASYNC
For the data length format of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(R8C) (UART0, UART1)
RAPI_BIT_7 Transfer data length 7 bits RAPI_BIT_8 Transfer data length 8 bits
RAPI_BIT_9 Transfer data length 9 bits
For the clock source of serial communication, the following values can be set.
(R8C) (UART0, UART1)
RAPI_CKDIR_INT Internal clock is used as the clock source of serial communication.
RAPI_CKDIR_EXT External clock is used as the clock source of serial communication.
For the stop bit length of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(R8C) (UART0, UART1)
RAPI_STPB_1 1 stop bit RAPI_STPB_2 2 stop bits
For the parity bit of clock asynchronous serial communication, the following values can
be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(R8C) (UART0, UART1)
RAPI_PARITY_NON No parity bit RAPI_PARITY_EVEN Even parity bit
RAPI_PARITY_ODD Odd parity bit
For the clock polarity of serial communication, the following values can be set.
If the API is used in clock asynchronous serial communication mode, do not set these
values.
(R8C) (UART0, UART1)
RAPI_DPOL_NON Polarity not inverted RAPI_DPOL_INV Polarity inverted
For the count source of the built-in baud rate generator, the following values can be set.
(R8C) (UART0, UART1)
RAPI_BCSS_F1 f1SIO RAPI_BCSS_F8 f8SIO
RAPI_BCSS_F32 f32SIO
For the transfer format, the following values can be set.
If the data length selected for use in clock asynchronous serial communication mode is
7 or 9 bits long, do not set these values.
(R8C) (UART0, UART1)
RAPI_LSB_SEL LSB first RAPI_MSB_SEL MSB first
(H8/300H)
RAPI_COM1 SCI3 channel 1 RAPI_COM2 SCI3 channel 2
Clock synchronous serial communication mode
Clock asynchronous serial communication mode
Rev.1.01 2007.02.16 RJJ10J1643-0101
26
Return value
RAPI_COM3 SCI3 channel 3
For serial communication mode, the following values can be set.
(H8/300H) (SCI3 channel 1, SCI3 channel 2, SCI3 channel 3)
RAPI_SM_SYNC
RAPI_SM_ASYNC
For the data length format of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(H8/300H) (SCI3 channel 1, SCI3 channel 2, SCI3 channel 3)
RAPI_BIT_7 Transfer data length 7 bits RAPI_BIT_8 Transfer data length 8 bits
For the clock source of serial communication, the following values can be set.
(H8/300H) (SCI3 channel 1, SCI3 channel 2)
RAPI_CKDIR_INT Internal clock is used as the clock source of serial communication.
RAPI_CKDIR_EXT External clock is used as the clock source of serial communication.
For the stop bit length of clock asynchronous serial communication, the following
values can be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(H8/300H) (SCI3 channel 1, SCI3 channel 2, SCI3 channel 3)
RAPI_STPB_1 1 stop bit RAPI_STPB_2 2 stop bits
For the parity bit of clock asynchronous serial communication, the following values can
be set.
If the API is used in clock synchronous serial communication mode, do not set these
values.
(H8/300H) (SCI3 channel 1, SCI3 channel 2, SCI3 channel 3)
RAPI_PARITY_NON No parity bit RAPI_PARITY_EVEN Even parity bit
RAPI_PARITY_ODD Odd parity bit
For the count source of the built-in baud rate generator, the following values can be set.
(H8/300H) (SCI3 channel 1, SCI3 channel 2 SCI3 channel 3)
RAPI_BCSS_F1 Φ clock RAPI_BCSS_F4 φ/4 clock RAPI_BCSS_F16 φ/16 clock RAPI_BCSS_F32 φ/64 clock
The noise rejection function can be set to be turned on or turned off.
When used in clock synchronous serial communication mode, the noise rejection
function has no effect.
(H8/300H) (SCI3 channel 3)
RAPI_NOISE_CANCEL_ON Noise rejection function turned on
RAPI_NOISE_CANCEL_OFF Noise rejection function turned off
[data2]
Sets the divide-by-N value of a communication speed.
If serial communication was successfully set, RAPI_TRUE is returned; if settings failed,
RAPI_FALSE is returned.
Clock synchronous serial communication mode
Clock asynchronous serial communication mode
Rev.1.01 2007.02.16 RJJ10J1643-0101
27
Functionality
Remark
Program example
Serial I/O
The specifiable serial ports differ with each CPU used.
If an undefined value is specified in the first argument, operation of the API cannot
be guaranteed.
#include ”rapi_sif_r8c_13.h”
Boolean func( void ) { /* Set the data of RAPI_COM1 to serial driver */ return _BasicSetSerialFormat(RAPI_COM1 | RAPI_SM_SYNC | RAPI_CKDIR_INT | RAPI_BCSS_F 1 | RAPI_DPOL_NON | RAPI_LSB_SEL,
20); }
Rev.1.01 2007.02.16 RJJ10J1643-0101
28
Loading...
+ 174 hidden pages