(c) UART serial communication

Source: Internet
Author: User

Uart:university asynchronous receiver and transmitter UART//Universal asynchronous receiver and transmitter

Why should have the serial port: Because many embedded device does not have the display, cannot obtain the real data information of the device, so can connect through UART serial port and HyperTerminal, print the output information of the embedded device. can also be traced and debugged via serial port.

such as equipment: Network routers, switches through the serial port configuration, GPS receiver through the serial port output GPS data received.

1, asynchronous communication technology: the sending and receiving side does not have synchronous clock, only the data line, but negotiated the protocol, (fixed frequency) for data sampling. That is, the baud rate bit per second guarantees correctness

2. Transmission mode: Polling mode, interrupt mode, DMA mode

3. s3c2440 UART Controller:

The UART receiver and transmitter contain a 64Bytes buffer (so divided into buffer mode and non-buffered mode)

4, Data frame: is the most basic communication unit of the UART, including the start bit, data bit, check bit, stop bit (both sides agreed data frame, specify the same baud rate, ensure data transmission synchronization)

Specifically, it is not difficult to see the chip manual related registers.

——————————————————————————————————————————————————————————————————————————

F:\arm+linux\ Embedded Development \work\armarch\uart_init

Startup code:

;; UART serial port experiment; Gpbcon EQU0x56000010Gpbdat EQU0x56000014Area Init, CODE, READONLY Entrystart; Close watchdog Ldr R0,=0x53000000put the watchdog control register address into r0 mov r1, #0str R1, [r0]; Sets the value of the watchdog control register to 0 BL Initmem; jumps to the Initmem code snippet, initializes the memory IMPORT Xmain ; Introduction of the Xmain function in Main.c Ldr sp,=0x34000000initialize the stack pointer to Ldr LR before calling the C program.=Loop; Set the return address of the Xmain function Ldr pc,=Xmain; Jump to the entrance of the Xmain function in C program to execute loop b loop; dead loop initmem; memory initialization Ldr R0,=0x48000000load Memory related register first address R0 LDR R1,=0x48000034load Memory related register tail address to R1 ADR R2, Memdata; load the first address of the Register configuration data address segment to R2initmemloop LDR R3, [R2], #4; Loop Setup Register registers STR r3, [R0], #4Teq r0, R1 bne initmemloop; Exit function when looping to the last register BX lrmemdata DCD0x22000000         ; Bwscon DCD0x00000700        ; BANKCON0 DCD0x00000700        ; BANKCON1 DCD0x00000700        ; BANKCON2 DCD0x00000700      ; BANKCON3 DCD0x00000700        ; BANKCON4 DCD0x00000700        ; BANKCON5 DCD0x00018005        ; BANKCON6 DCD0x00018005        ; BANKCON7 DCD0X008E07A3        ; REFRESH DCD0x000000b1        ; Banksize DCD0x00000030        ; MRSRB6 DCD0x00000030        ; MRSRB7 END
Init.s

Xmain function

1 /*xmain.c*/2 3 /*GPIO Registers*/4 #defineGphcon (* (volatile unsigned long *) 0x56000070)5 #defineGphdat (* (volatile unsigned long *) 0x56000074)6 #defineGphup (* (volatile unsigned long *) 0x56000078)7 8 /*UART Registers*/9 #defineULCON0 (* (volatile unsigned long *) 0x50000000)Ten #defineUCON0 (* (volatile unsigned long *) 0x50000004) One #defineUFCON0 (* (volatile unsigned long *) 0x50000008) A #defineUMCON0 (* (volatile unsigned long *) 0x5000000c) - #defineUTRSTAT0 (* (volatile unsigned long *) 0x50000010) - #defineUTXH0 (* (volatile unsigned char *) 0x50000020) the #defineURXH0 (* (volatile unsigned char *) 0x50000024) - #defineUBRDIV0 (* (volatile unsigned long *) 0x50000028) -   - #defineTxd0ready (1<<2)//Send data status OK + #defineRxd0ready (1)//Receive data status OK -      + /*UART serial Port initialization*/ A voidUart_init () at { -Gphcon |=0xa0;//Gph2,gph3 used as txd0,rxd0 -Gphup =0x0;//Gph2,gph3 Internal Pull-up -ULCON0 =0x03;//8N1 -UCON0 =0x05;//Query mode is polling or interrupt; clock selection is PCLK -UFCON0 =0x00;//do not use FIFO inUMCON0 =0x00;//do not use flow control -UBRDIV0 = A;//baud rate is 57600,pclk=12mhz to } +  - /*UART Serial Port single character printing function*/ the extern voidPUTC (unsignedCharc) * { $      while( ! (UTRSTAT0 &txd0ready));Panax NotoginsengUTXH0 =C; - } the  + /*UART Serial Port accepts a single character function*/ A externUnsignedCharGetcvoid) the { +      while( ! (UTRSTAT0 &rxd0ready)); -     returnURXH0; $ } $  - /*UART Serial string print function*/ - extern intPrintkConst Char*str) the { -     inti =0;Wuyi      while(Str[i]) { thePUTC ((unsignedChar) str[i++] ); -     } Wu     returni; - } About  $__inlinevoidDelayintmsec) - { -     intI, J; -      for(i = +; i >0; i--) A          for(j = msec*Ten; J >0; j--) +             /* do nothing*/; the } -  $ /*Xmain printing strings via UART serial port*/ the intXmain () the { the uart_init (); the      while(1) -     { inDelayTen); thePrintk"UART serial printing test \ r \ n"); the     } About    //return 0; This is omitted so that it does not appear statement is unreachable the}

Burn to nor flash, yourself to the Super terminal own groping!!!! (Reference: Yang Ji P151 page)

(c) UART serial communication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.