LPC54100 LPC54101 LPC54102 LPC541xx series serial port usage
(Using library, interrupt mode, no FIFO)
// Initialization function
void uart_init(baudRate)
{
UART_BAUD_T baud;
UART_CFG_T cfg;
// Enable the clock
Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_FRG);
//Configure baud rate
//Get the clock frequency
baud.clk = Chip_Clock_GetAsyncSyscon_ClockRate();
//Desired baud rate
baud.baud = baudRate;
baud.ovr = 0;
baud.mul = 0;
baud.div = 0;
if (ROM_UART_CalBaud(&baud) != LPC_OK) {
// Failed to calculate the frequency division coefficient
printf("Error calculating baud ratern");
}
/* Set the fractional divider */
Chip_SYSCON_SetUSARTFRGCtrl(baud.mul, 0xFF);
// Enable serial port 0 clock
Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_USART0);
//Configure IO ports P0.0 and P0.1 as serial port functions
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 0, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 1, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGITAL_EN));
//Get the space required by the serial port
size = ROM_UART_GetMemSize();
//Apply for the space required by the serial port
drv_mem = (uint32_t *)malloc(size);
//Call the initialization function to initialize serial port 0
UART0 = ROM_UART_Init(drv_mem, LPC_USART0_BASE, NULL);
//Configure the serial port
//8-bit data enable receive interrupt
cfg.cfg = UART_CFG_8BIT | UART_CFG_BRKRX;
//Set the frequency division value, directly use the result calculated by ROM_UART_CalBaud
cfg.div = baud.div;
cfg.ovr = baud.ovr;
cfg.res = UART_BIT_DLY(baudRate);
//Configure serial port 0
ROM_UART_Configure(UART0, &cfg);
// Enable interrupt
NVIC_ClearPendingIRQ(UART0_IRQn);
NVIC_EnableIRQ(UART0_IRQn);
LPC_USART0->INTENSET |= (1<<0);
}
//Interrupt service function
void UART0_IRQHandler(void)
{
uint8_t that;
//Send interrupt
if (LPC_USART0->INTSTAT & (1<<2))
{
//Wait for sending to complete
ROM_UART_WaitTx(UART0);
}
//Receive interrupt
if (LPC_USART0->INTSTAT & (1<<0))
{
//Read data
dat = LPC_USART0->RXDAT;
printf("%c", dat);
}
}
Previous article:Bare metal program 2: GPIO lights up the LED lamp assembly
Next article:Can both Cortex-M3 and Cortex-M0 operate with bit-banding?
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to carry out wireless monitoring in harsh outdoor environments?
- I have basic knowledge of embedded C programming and almost no knowledge of digital electronics. How long will it take to self-study FPGA to Ethernet communication?
- [Ended] Buy now: Free shipping for new users of e-Network is about to end, post your order and leave a message to get a surprise~
- Chip plagiarism, fined 4 million yuan!
- TIOBE August 2022 Ranking
- Reading Notes of the Good Book "Electronic Engineer Self-study Handbook" 02-Keil uVision4 & STC
- I received the book on the basics of power supply design and I feel it is necessary to share it
- IEC61000-4-5 coupling mode
- Brushless servo, no Hall drive, electric vehicle controller (with Hall sine wave)
- [AT-START-F403A Review] 5. Simulate the SPI screen and find a problem