Preface: It seems that it's not possible to use the debug USB port as debugger and serial port at the same time.
I'm evaluating the Renesas RX65N MCU EV Kit. In this post: Serial communication - UART - SCI. |
The RX family has 12 serial peripherals. Luxury. And the RX65N supports all of them.
* CH# 110 111 113 130 210 230 231 23T 24T 24U 63N 631 64M 71M 65N
* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
* CH0 X X X X X X* X X X X
* CH1 X X X X X X X X X X X X X X X
* CH2 X X X X X X
* CH3 X X X X X
* CH4 X X X X X
* CH5 X X X X X X X X X X X X X X X
* CH6 X X X X X X X X X X X X
* CH7 X X X X X
* CH8 X X X X X X X X X
* CH9 X X X X X X X X X
* CH10 X X X
* CH11 X X X X
* CH12 X X X X X X X X X X X X
These blocks can be used as SCI/UARTs, I2C or SPI devices.
On the Envision board, SCI channel 5 is connected to the debug USB port.
Channel 9 is broken out to the PMOD connector. Other ones are availabe from different locations on the board too.
In this example I'm using SCI channel 9. That allows me to keep using the debug USB for debugging.
A logic level to USB converter is required. There are (FTDI) cables that can do that (or a Bus Pirate). I'm using the debug section of a TI LaunchPad.
PMOD pin 10 is RX, pin 9 TX and pin 11 GND. With these 3 pins you can make a connection to your logic -> USB converter.
Renesas' RX65 example
The SCI application note for SCI comes with an example for a different RX65N board. That board has SCI2 linked to the USB and runs a 24 MHz crystal clock.
In our case, SCI2 is linked o USB and the crystal is a 12 MHz one.
Because we're using channel 9 and a different clock, there are some changes to be made:
in r_config/r_bsp_config.h, change the crystal frequency from 24 MHz to 12 MHz:
/* Input clock frequency in Hz (XTAL or EXTAL). */ #define BSP_CFG_XTAL_HZ (12000000)
Then, in r_config/r_sci_rx_config.h, enable serial channel 9:
#define SCI_CFG_CH9_INCLUDED (1)
In the main() function, adapt the init code to use channel 9:
my_sci_err = R_SCI_Open(SCI_CH9, SCI_MODE_ASYNC, &my_sci_config, my_sci_callback, &g_my_sci_handle);
Also change the LED flash functionality in the SCI interrupt handler.
The LED toggles whenever you send a character to the SCI.
Our board has user LED2 linked to Port 7 pin 0:
In r_bsp/board/rskrx65n_2mb/rskrx65n_2mb.h, alter the definitions of LED 2:
/* LEDs */ // ... #define LED2 PORT7.PODR.BIT.B0 // ... #define LED2_PDR PORT7.PDR.BIT.B0
In the SCI callback, also change to LED2:
if (args->event == SCI_EVT_RX_CHAR) { /* From RXI interrupt; received character data is in args->byte */ LED2 = ~LED2; // Toggle LED to demonstrate callback execution. nop(); }
Then, change the pin assignment function to use channel 9:
static void sci_rx65N_2M_init_ports(void) { R_BSP_RegisterProtectDisable(BSP_REG_PROTECT_MPC); // Use BSP function to unlock the MPC register. // jc 20191207: // TXD9 PB7 78 // RXD9 PB6 79 /* Initialize channel 9 TXD and RXD pins */ PORTB.PODR.BIT.B7 = 0; // Set PB7(78) signal state low (power-up default) MPC.PB7PFS.BYTE = 0x0A; // Assign PB7(78) to TXD2 function MPC.PB6PFS.BYTE = 0x0A; // Assign PB6(79)) to RXD2 function R_BSP_RegisterProtectEnable(BSP_REG_PROTECT_MPC); // Re-lock the MPC register. PORTB.PDR.BIT.B7 = 1; // Set PB7(78) direction to output (for use as TXD) PORTB.PDR.BIT.B6 = 0; // Set PB6(79) direction to input (for use as RXD) PORTB.PMR.BIT.B7 = 1; // Set PB7(78) mode to peripheral operation PORTB.PMR.BIT.B6 = 1; // Set PB6(79) mode to peripheral operation return; }
Test
To test the example, you have to connect your USB -> logic level translator to the PMOD connector.
Use the below table as guideline.
PMOD pin | RX65N Function |
---|---|
PMOD 9 | SCI 9 TX |
PMOD10 | SCI 9 RX |
PMOD 11 | GND |
Then use a serial terminal program to connect to that translator, speed 115200, no parity, 1 stop:
Set the traffic for no cho. The firmware will echo when needed:
Connect, Then start the program.
You need to type "any key" (use enter) to start the communication.
First, the terminal will show the SCI FIT module version:
After that, each character you type in the terminal will be echo'd by the device.
If the LED2 does not flash when you type a character in your terminal, swap the RX and TX connections and try again.
The e2 studio project is attached.
Top Comments