Summary of mini2440 serial port module

Publisher:咖啡小熊Latest update time:2022-10-11 Source: csdnKeywords:mini2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Working principle of serial port:

1. From the above serial port circuit, we can know that the specific process is as follows:


Send: write data - > buffer - > shifter - > TXDn - > RSTXDn - > PC


Receive: PC---》RSRXDn---》RXDn--->shifter--->buffer--->get data


2. As can be seen from the above figure,


The buffer has two modes, FIFO mode and Non-FIFO mode.


If FIFO mode is used, the FIFO Register needs to be configured so that 64 bytes of buffer are available.


If Non-FIFO mode is used, there is no need to configure the FIFO Register, but only one byte of buffer is available.


3. The specific process of making a serial port module:


<1>. From the serial port circuit diagram, we can know that we should first configure the corresponding pins to the corresponding functional mode. Here we can see that the corresponding pin is GPH.


<2>. From the user manual we need to configure the corresponding registers one by one.


Here we use the Non-FIFO mode first. After browsing, we can obtain the following information:


First: We need to configure the frame format settings (ULCON0).


Second: We need to configure the working mode (UCON0). (The working mode includes DMA interrupt polling mode. We use the polling mode here first).


Third: We need to configure the baud rate.


Note: For the status register, we do not need to configure it unless there are special requirements.


So in summary: for the serial port module, we need to do the following 4 steps:


1. Pin settings


2. Frame format settings


3. Working mode setting (DMA interrupt polling)


4. Baud rate setting.


The following is the source code based on the mini2440 serial port module:


/************************************************

  NAME    : UART.C

  DESC   :

  Revision: 2015.8.18 ver 0.0

 ************************************************/

 #include "uart.h"

 #include

 #include

 

/***********************************************

Function  name  :   uart_init

Description: uart initialization

Input parameter :   none

Return          :   none   

Others      :   uart init                                      

*************************************************/


 void uart_init()

 {

  

  //1. Configure the corresponding bits of sending and receiving of serial port 0 in GPHCON

  rGPHCON &= ~(0xf<<4);

  rGPHCON |=(0xa<<4);

  

  //2. Set how many data bits can be transmitted at a time

  rULCON0 |= (0x3<<0);

  

  //3. Configure the serial port controller to set the sending and receiving mode. Sending is DMA mode and receiving is polling mode.

  rUCON0 |= (0x9<<0);

  //rUCON0 = 0<<12|0<<10|0<<4|1<<2|1;

  //4. Set the baud rate

  rUBRDIV0 = (int)(PCLK/(BAUDRATE*16)) - 1;

 }

/***********************************************

Function  name  :   getc

Description: Receive data

Input parameter :   none

Return          :   char   

Others      :   none                                     

*************************************************/


 unsigned char uart_getc(void)

 {

  unsigned char ret;

  while((rUTRSTAT0 & (1<<0))==0);

  right = rURXH0;

  if(ret == 'r')

       right = 'n';

       

 return right; 

 }

/***********************************************

Function  name  :   myputc

Description: Send data

Input parameter :   char

Return          :   none   

Others      :   none                                      

*************************************************/


 void myputc(unsigned char ch)

 {

  if(ch=='n')

        myputc('r');

 while((rUTRSTAT0 & 2) == 0);

 

 rUTXH0 = ch; 

 }

/***********************************************

Function  name  :   send_string

Description: Send string

Input parameter :   char *

Return          :   none   

Others      :   none                                      

*************************************************/


 void uart_puts(const char *str)

 { 

  while(*str)

 {  

  myputc(*str);

  str++; 

 }

 myputc ( ' n ' ) ;

 }

/***********************************************

Function  name  :   mygets

Description: Receive string

Input parameter :   char *

Return          :   none   

Others      :   none                                      

*************************************************/


void mygets(char *str)

{

 S32 i=0;

 U8 ch;

 while((ch=uart_getc())!='n')

 {

  if(ch=='b')

  {

   if(i>0)

   {

    myputc('b');

    myputc(' ');

    myputc('b');

    i--;

   }

  }

  else

  {

   str[i++] = ch;

   myputc ( ch ) ;

  }

 }

 str[i]='';

 myputc ( ' n ' ) ;

 

}

/***********************************************

Function  name  :   uart_printf

Description: Send message

Input parameter :   char *fmt....

Return          :   none   

Others      :   none                                      

*************************************************/

void uart_printf(char *fmt,...) //Function with variable parameters

{

    va_list ap; //Initialize the pointer to the variable parameter list

   char string[256];


 va_start(ap,fmt); //Pay the address of the first variable parameter to ap, that is, ap points to the beginning of the variable parameter list

 

 vsprintf(string,fmt,ap); //Convert the variable parameters pointed to by parameters fmt and ap into a formatted string and put it in the string array. It has the same function as sprintf(), but the parameter types are different.

 uart_puts(string); //Send the formatted string from the development board serial port

 

 va_end(ap); //ap is set to 0, which is not very useful, but is mainly for program robustness


}


Keywords:mini2440 Reference address:Summary of mini2440 serial port module

Previous article:About mini2440 interrupt configuration
Next article:About the configuration of mini2440 key interrupt

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号