S5PV210 serial communication programming practice-2

Publisher:科技思想家Latest update time:2022-08-04 Source: csdnKeywords:S5PV210 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. GPIO initialization corresponding to serial port Tx and Rx

Assign corresponding values ​​to the corresponding bits of GPA0CON using C language bit operations.

void uart_init( void )

{

//Initialize the GPIO pins corresponding to Tx and Rx

rGPA0CON &= ~( 0xff << 0 ); // Clear all bits 0 to 7 of the register

rGPA0CON |= 0x00000022; //0b0010, Rx, Tx

}


2. Main control registers such as UCON, ULCON, UMCON, and UFCON

Just set it up according to the values ​​analyzed in the previous section.

void uart_init( void )

{

//Initialize the GPIO pins corresponding to Tx and Rx

rGPA0CON &= ~( 0xff << 0 ); // Clear all bits 0 to 7 of the register

rGPA0CON |= 0x00000022; //0b0010, Rx, Tx


//Settings of several key registers

rULCON0 = 0x3;

rUCON0 = 0x5;

rUMCON0 = 0x0;

rUFCON0 = 0x0;


}

//Baud rate setting DIV_VAL = ( PCLK / (bps x 16) ) - 1 DVI_VAL = (66000000 / (115200 X 16 )) -1 = 34.8 remainder 0.8


//PCLK_PSYS uses 66MHz

//rUBRDIV0 = 34

//rUDIVSLOT0 = 0xdfdd;


//PCLK_PSYS uses 66.7MHz

//DVI_VAL = (66700000 / (115200 X 16 )) -1 = 35.18 remainder 0.18

rUBRDIV0 = 35

//(number of 1s in rUDIVSLOT) / 16 = remainder calculated in the previous step = 0.18

(Number of 1s in rUDIVSLOT) = 16 x 0.18 = 2.88 = 3 (3 1s to find the recommendation table)

rUDIVSLOT0 = 0x0888; //3 1s, look up the table to get this number


3. Calculation and setting of baud rate

(1) The first step is to use PCLK_PSYS and the target baud rate to calculate DIV_VAL = (PCLK / (bps x 16)) - 1

(2) In the second step, the integer part of DIV_VAL is written into the UBRDIV0 register.

(3) In the third step, multiply the decimal part by 16 to get the number of 1s, and then look up the table to get the setting value of the uBDIVSLOT0 register.


4. Writing of serial port sending and receiving functions

//Serial port sending program, send 1 character

void uart_putc( char c )

{

//The serial port sends a character, which actually throws a byte into the send buffer (that is, the UTXH0 register).

rUTXH0 = c;

rUTXH0 = a;

//If you send like the above, the CPU is too fast (because there is no interrupt) and the serial port cannot handle it. At this time, you need to read a status register (UTRSTAT0 register)

//Because the speed at which the serial port controller sends 1 byte is much lower than the speed of the CPU, the CPU must confirm that the current buffer of the serial port controller is empty before sending 1 byte (which means that the serial port has sent the previous byte)

//If the buffer is not empty (UTRSTAT0 register) bit 1 is 0, it should loop until (UTRSTAT0 register) bit 1 is 1.

while( !(rUTRSTAT0 & (1 << 1 ) ) ); //Judge whether the buffer is empty

rUTXH0 = c;

}


(1) Write a sending function. Before sending, use a while loop to wait until the sending buffer is empty.


(2) Serial port receiving program, polling mode, receives one byte

char uart_getc( void )

{

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

return ( rURXH0 & 0x0f );

}

5. Comprehensive debugging

void main( void )

{

uart_init();

while( 1 ) //keep sending character a

{

uart_putc( 'a' );

delay(); //delay function

{

}

6. Extended Exercise - Debug after changing the baud rate


Check the clock diagram to find the clock source:

insert image description here

Baud rate calculation:

insert image description here
insert image description here

Send and receive status register:

insert image description here

Keywords:S5PV210 Reference address:S5PV210 serial communication programming practice-2

Previous article:Introduction to the interrupt system of S5PPV210
Next article:S5PV210 Serial Communication Programming Practice - 1

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号