RX Family
ADC Module Using Firmware Integration Technology
R01AN1666EJ0220 Rev. 2.20
Page 54 of 74
Dec 01, 2016
usage), a callback function is required. This function is called by the interrupts whenever a scan has
completed with an argument indicating which scan completed.
To set values of parameters used in this function, first clear all members of parameters to 0, and then set values.
Reentrant
No. For MCUs with a single unit this function should only be called once before a call to Close(). For the
RX64M/RX71M/RX65x this function may be called once for each unit.
Example
(RX110, RX111, RX113)
adc_cfg_t config;
/* Clear all fields of the adc_cfg_t structure */
memset(&config, 0, sizeof(config));
/* INITIALIZE FOR SINGLE SCAN OF TEMPERATURE SENSOR
* - use software trigger to start scan; poll for completion
* - don't do any summing of conversion values
* - keep the data registers aligned right, and clear after reading is off
* - use normal speed conversion
*/
config.trigger = ADC_TRIG_SOFTWARE;
config.priority = 0; // denotes polling!
config.add_cnt = ADC_ADD_OFF;
config.alignment = ADC_ALIGN_RIGHT;
config.clearing = ADC_CLEAR_AFTER_READ_OFF;
config.conv_speed = ADC_CONVERT_SPEED_NORM;
R_ADC_Open
(0, ADC_MODE_SS_TEMPERATURE, &config, FIT_NO_FUNC);
Special Notes (RX Family Common):
The application must complete MPC and PORT initialization prior to calling Open().
Refer to the User’s
Hardware Manual about limitations of using output pins on the same port as analog pins
. The following is a sample
initialization for an RSKRX111 Rev 1 board:
R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_MPC);
MPC.P40PFS.BYTE = 0x80; // Pin Func Select P40 AN000
PORT4.PDR.BIT.B0 = 0; // set AN pin direction to input (dflt)
PORT4.PMR.BIT.B0 = 1; // set AN pin mode to peripheral
MPC.PB0PFS.BIT.PSEL = 0x09; // Pin Func Select PB0 ADTRIG0; SW3 on RSKRX111
PORTB.PDR.BIT.B0 = 0; // set ADTRIG0 pin direction to input (dflt)
PORTB.PMR.BIT.B0 = 1; // set ADTRIG0 pin mode to peripheral
R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_MPC);
The application must set the A/D conversion clock (PCKD) prior to calling Open().Refer to User’s Hardware Manual
for PCLKB/ADCLK frequency ratios.
If a Continuous mode is selected, it is recommended not to use the S12ADI interrupt. That causes the majority of the
processing time to be spent at the interrupt level.
If interrupts are in use, a callback function is required which takes a single argument. This is a pointer to a structure
which is cast to a void pointer (provides consistency with other FIT module callback functions). See type
adc_mode_t
in section 2.10 for the MCU being used.