UART driver code template of S3C2440 (realview MDK)

Source: Internet
Author: User
Tags file handling

Note that it is not as easy as writing a pen. To make it easier to view code and reuse code again, we will post the S3C2440 UART driver code here. Use the friendly mini2440 Development Board and the development environment is realview MDK 4.22. In this Code, the initialization of gpio is completed in S3C2440. s and configured in the HTML method provided by Keil.

The source code structure is simple and clear. For the original project, click the open link.


UART Controller initialization:

void Uart_Init(void){#define rULCON0(*(volatile unsigned int*)0x50000000)#define rUCON0(*(volatile unsigned int*)0x50000004)#define rUBRDIV0(*(volatile unsigned int*)0x50000028)#define PCLK50000000#define BUADRATE115200rULCON0 = 0x03;//No parity, One stop bit, 8-bits datarUCON0= 0x05;//Tx Enable, Rx Enable, PCLK as source clockrUBRDIV0 = (int)(PCLK / (BUADRATE * 16)) - 1;//115200bps}

Character sending function:

void Uart_Putc(unsigned char c){#define rUTRSTAT0(*(volatile unsigned int*)0x50000010)#define rUTXH0(*(volatile unsigned int*)0x50000020)#define BUFFER_EMPTY(1 << 1)while(!(rUTRSTAT0 & BUFFER_EMPTY));rUTXH0 = c;}

Character receiving function:

unsigned char Uart_Getc(void){#define rUTRSTAT0(*(volatile unsigned int*)0x50000010)#define rURXH0(*(volatile unsigned int*)0x50000024)#define BUFFER_READY(1 << 0)while(!(rUTRSTAT0 & BUFFER_READY));return rURXH0;}

To use the printf library function, perform the following re- ing:

struct __FILE  {  int handle;  /* Whatever you require here. If the only file you are using is */  /* standard output using printf() for debugging, no file handling */  /* is required. */  };  /* FILE is typedef'd in stdio.h. */  FILE __stdout;  int fputc(int ch, FILE *f) {     Uart_Putc(ch);          return ch; } int ferror(FILE *f) {  /* Your implementation of ferror */  return EOF;}

Test code:

int main(void){unsigned char ch;//clock_init();Uart_Init();printf("%s, %d", __FILE__, __LINE__);while(1){ch = Uart_Getc();Uart_Putc(ch);}}


UART driver code template of S3C2440 (realview MDK)

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.