Presentation is loading. Please wait.

Presentation is loading. Please wait.

UART: Universal Asynchronous RX/TX

Similar presentations


Presentation on theme: "UART: Universal Asynchronous RX/TX"— Presentation transcript:

1 UART: Universal Asynchronous RX/TX
4/29/2015 Richard Kuo Assistant Professor

2 OutLine 9.0 NuMicro_UART.ppt UART Interface Introduction
Ex. UART to Bluetooth module (smpl_UART1_HC05) Ex. UART to WiFi module (smpl_UART1_ESP1) Ex. RS485 Basic Transmission (smpl_RS485) Ex. UART1 to Bluetooth module & I2C to MEMS sensor (smpl_HC05_MPU6050) HC-05 (BT2.0) HC-08 (BLE) ESP-12 (WiFi)

3 UART pins NUC140 LQFP 100pin UART0 RX0/GPB0 : pin32 TX0/GPB1 : pin33
RX2/GPD14 : pin38 TX2/GPD15 : pin39 Nano102 LQFP 64pin UART0 RX0: PB1(pin61) or PA13(pin57) TX0: PB0(pin60) or PA12(pin56) UART1 RX1: PC7(pin14) or PF2(pin 42) TX1: PC8(pin15) or PF3(pin 43)

4 UART pins of Nano102 LQFP-64 UART1 UART0 Nano102SC2AN

5 UART pins of NUC140 LQFP-100 UART2 UART0 NUC140VE3CN UART1

6 UART (Universal Asynchronous Receiver Transimitter)
Serial Transmit Start Bit Data Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Parity Stop Drive LSB MSB Sample Sample Sample Sample Sample Sample Sample Sample Sample Sample Sample Serial Receive Start Bit Data Bit 0 Data Bit 1 Data Bit 2 Data Bit 3 Data Bit 4 Data Bit 5 Data Bit 6 Data Bit 7 Parity Bit Stop Bit LSB MSB

7 RS-232 DB9 Connector 1 2 3 4 5 6 7 8 9 Data Carrier Detect
Data Set Ready Receive Data Request To Send Clear To Send Ring Indicator Transmit Data Data Terminal Ready Signal Ground

8 UART Baud Rate Setting vs Oscillator Frequencies

9 RS-232/422/485 Comparison RS-232 RS-422 RS-485 No. of Driver 1 32
No. of Receiver 10 Mode of Operation Half duplex Full duplex Max. Distance 15m 1200m Max. Speed at 12m 20Kbps 10Mbps 35Mbps Max. Speed at 1200m 1Kbps 100Kbps Min. Output Voltage +-5V +-2.0V +-1.5V Max. Output Voltage +-25V +-6V -7~12V Receiver Input Range +-15V +-10V

10 Nu-LB-NUC140 UART w RS232 transceiver
connector RS232 Transceiver

11 UART schematic to DB9 pin2 RX SP232-TX from DB9 pin3 TX SP232-RX

12 NuMicro MCU UART function
NuMicro provide up to 3 UART ports (some support up to 2 ports) programmable baud-rate programmable serial-interface Built-in TX/RX buffers (FIFO) : 16 bytes Support hardware flow-control (/CTS及/RTS) on UART0 & UART1 Support IrDA SIR function (Infrared transmission use)

13 UART Clock Selection of Nano102
12/16MHz ~32/50MHz 32768Hz 12~24MHz

14 UART Clock Selection of NUC140
HIRC PLL HXT

15 UART Block Diagram

16 UART function call UART_Open(UARTn, Baudrate); UART_Open(UART1, 9600);
UART_Read(UARTn, ReadBuffer, No_of_bytes); UART_Read(UART1, RX_Buffer, 8); UART_Write(UARTn, WriteBuffer, No_of_bytes); UART_Write(UART1, TX_Buffer, 8);

17 UART Clock & Pins setting (Nano102)
// Select IP clock source CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UART_S_HIRC, CLK_UART_CLK_DIVIDER(3)); // 12/3=4MHz // Enable IP clock CLK_EnableModuleClock(UART1_MODULE); // Init I/O // Set PC multi-function pins for UART0 RXD, TXD SYS->PC_L_MFP &= ~(SYS_PC_L_MFP_PC7_MFP_Msk); SYS->PC_L_MFP |= (SYS_PC_L_MFP_PC7_MFP_UART1_RX); // Nano102 LQFP64-pin14 SYS->PC_H_MFP &= ~(SYS_PC_H_MFP_PC8_MFP_Msk); SYS->PC_H_MFP |= (SYS_PC_H_MFP_PC8_MFP_UART1_TX); // Nano102 LQFP64-pin15

18 UART Clock & Pins setting (NUC140)
// Select IP clock source CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_UART_CLK_DIVIDER(3)); // 12/3=4MHz // Enable IP clock CLK_EnableModuleClock(UART1_MODULE); // Init I/O // Set PB multi-function pins for UART1 RXD, TXD // Set PB multi-function pins for UART1 RXD and TXD SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB4_Msk | SYS_GPB_MFP_PB5_Msk); SYS->GPB_MFP |= (SYS_GPB_MFP_PB4_UART1_RXD | SYS_GPB_MFP_PB5_UART1_TXD);

19 UART Port & INT Initialization
void Init_HC06(void) { UART_Open(UART1,9600); // enable UART1 at 9600 baudrate UART_ENABLE_INT(UART1, UART_IER_RDA_IE_Msk); NVIC_EnableIRQ(UART1_IRQn); }

20 UART IRQ Handler #define RXBUFSIZE 8
volatile char RX_buffer[RXBUFSIZE]; void UART1_IRQHandler(void) { uint32_t u32IntSts= UART1->ISR; // UART interrupt status bit if(u32IntSts & UART_IS_RX_READY(UART1)) { UART_Read(UART1, RX_buffer, RXBUFSIZE); printf("%s\n", RX_buffer); }

21 UART Protocol Setting Even, odd or no-parity 5 ~ 8bits 1 ~ 2bits
UART_Open(port, baudrate) uart->TLCTL = UART_WORD_LEN_8 | UART_PARITY_NONE | UART_STOP_BIT_1 | UART_TLCTL_RFITL_1BYTE | UART_TLCTL_RTS_TRI_LEV_1BYTE;

22 UART Auto Flow Control

23 UART Wake-Up Cases

24 UART Wake-Up Cases

25 UART Wake-Up Cases

26 UART CTSn Wake-Up Cases

27 UART with PWM modulation
Nano100Series

28 IrDA Block Diagram

29 IrDA TX/RX Timing Diagram

30 RS485 connected to the transceiver
RTS level setting RTS signal pin as TX OE

31 LIN bus Frame

32 Bluetooth module (HC-05)
Connections N.C. MCU TX MCU RX GND VCC HC-05 can operate at 5V

33 Add Bluetooth Device device added com port no.
Note: after the device is added, check its property to find its com port number

34 Open PC HyperTerminal

35 Select HyperTerminal connecting com port

36 Setup com port parameter

37 See output on HyperTerminal

38 smpl_UART1_HC05

39 smpl_UART1_HC05 // // smpl_UART1_HC05 // Board : NuTiny-EVB-Nano102 // MCU : Nano102SC2AN (LQFP64) // Module : HC-05 (Bluetooth 2.0) // Features : // UART1 to HC05 : transmit/receive data through Bluetooth // baudrate=9600, databit=8, stopbit=1, paritybit=0, flowcontrol=None // Connections // STATE N.C. (LED indication) // RXD to PC8 /UART1-TX (Nano102SC2AN LQFP64 pin15) // TXD to PC7 /UART1-RX (Nano102SC2AN LQPF64 pin14) // GND to Gnd // VCC to Vcc (3.3~6V) // EN N.C. (AT command mode)

40 smpl_UART1_HC05 #include <stdio.h> #include <math.h> #include <string.h> #include "Nano1X2Series.h" #define RXBUFSIZE 8 // Global variables volatile char RX_buffer[RXBUFSIZE]; void UART1_IRQHandler(void) { uint32_t u32IntSts= UART1->ISR; if(u32IntSts & UART_IS_RX_READY(UART1)) { UART_Read(UART1, RX_buffer, RXBUFSIZE); printf("%s\n", RX_buffer); }

41 smpl_UART1_HC05 void Init_HC06(void) { UART_Open(UART1,9600); // enable UART1 at 9600 baudrate UART_ENABLE_INT(UART1, UART_IER_RDA_IE_Msk); NVIC_EnableIRQ(UART1_IRQn); } int32_t main() SYS_Init(); Init_HC06(); printf(“Nano102 is running \n”); while(1) {

42 Important Notice ! This educational material are neither intended nor warranted for usage in systems or equipment, any malfunction or failure of which may cause loss of human life, bodily injury or severe property damage. Such applications are deemed, “Insecure Usage”. Insecure usage includes, but is not limited to: equipment for surgical implementation, atomic energy control instruments, airplane or spaceship instruments, the control or operation of dynamic, brake or safety systems designed for vehicular use, traffic signal instruments, all types of safety devices, and other applications intended to support or sustain life. All Insecure Usage shall be made at user’s own risk, and in the event that third parties lay claims to the author as a result of customer’s Insecure Usage, the user shall indemnify the damages and liabilities thus incurred by using this material. Please note that all lecture and sample codes are subject to change without notice. All the trademarks of products and companies mentioned in this material belong to their respective owners.


Download ppt "UART: Universal Asynchronous RX/TX"

Similar presentations


Ads by Google