2228 views|1 replies

1140

Posts

0

Resources
The OP
 

Mini2440 serial communication [Copy link]

1. Serial port programming general block diagram
Mini2440 serial port communication (UART0)

二、分步介绍
#define GPHCON (*(volatile unsigned long *)0x56000070)
#define ULCON0 (*(volatile unsigned long *)0x50000000)
#define UCON0 (*(volatile unsigned long *)0x50000004)
#define UBRDIV0 (*(volatile unsigned long *)0x50000028)
#define UTRSTAT0 (*(volatile unsigned long *)0x50000010)
#define UTXH0 (*(volatile unsigned long *)0x50000020)
#define URXH0 (*(volatile unsigned long *)0x50000024)

#define PCLK 50000000
#define BAUDRATE 115200

1. Initialization

①、Configure pin function

GPHCON &= (~(0b11<<4))|(~(0b11<<6));//Port clear
GPHCON |= (0b10<<4)|(0b10<<6);//Set function [attach] 455487 [/attach]

②、Set data format

ULCON0 = (0b11<<0) | (0b0<<2) | (0b000<<3);

Set to No parity; One stop bit per frame; 8-bits

③. Set working mode

UCON0 = (0b01<<0) | (0b01<<2);

Both sending and receiving are set to Interrupt request or polling mode

④. Set the baud rate

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

In this experiment, UART0 uses PCLK

2. Send data

void putc(unsigned char ch)
{
while( !(UTRSTAT0 & (1<<2)));
UTXH0 = ch;
}

Only the lower eight bits are used

3. Receive data

unsigned char getc()
{
while( !(UTRSTAT0 & (1<<0)));
return URXH0;
}

Only the lower eight bits are used

image.png (20.95 KB, downloads: 0)

image.png
This post is from DSP and ARM Processors

Latest reply

Help, help, help, help, help   Details Published on 2020-1-8 08:22
 

45

Posts

0

Resources
2
 
Help, help, help, help, help
This post is from DSP and ARM Processors
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list