串行通讯
双线 uart (全双工 异步)
双线 iic (半双工 同步)
三线 spi (全双工 同步)
并行通讯
多根数据线 地址线,如 内存
硬件连接图:
寄存器:
GPA1CON
ULCON2
UCON2
UBRDIV2
UFRACVAL2
UTXH2
UTRSTAT2
UART传输的配置代码:
#define GPA1CON (*(volatile unsigned int *)0x11400020)
#define ULCON2 (*(volatile unsigned int *)0x13820000)
#define UCON2 (*(volatile unsigned int *)0x13820004)
#define UBRDIV2 (*(volatile unsigned int *)0x13820028)
#define UFRACUAL2 (*(volatile unsigned int *)0x1382002c)
#define UTXH2 (*(volatile unsigned int *)0x13820020)
#define UTRSTAT2 (*(volatile unsigned int *)0x13820010)
void uart_init(void)
{
// config pin GPA1_1 GPA1_0 uart mode
GPA1CON = 0x22;
// set uart function block
ULCON2 = 0x03; //data bit = 8 parity = none stop bit = 1
UCON2 = 0X05; //set plling mode
/*
* set Band- Rate = 115200
* DIV_VAL = (100000000/(115200 * 16)) -1 = 53.253
* UBRDIV2 = 53
* UFRACAL2 = 0x253 * 16 = 4
*/
UBRDIV2 = 53;
UFRACVAL2 = 4;
}
void putc(char c)
{
while(1)
{
if(UTRSTAT2 & 0x02)
{
break;
}
}
UTXH2 = c;
}
int main(void)
{
uart_init();
while(1)
{
delayis(); //汇编调用
putc('d');
}
return 0;
}
Makefile :
all:
arm-none-linux-gnueabi-gcc -fno-builtin -nostdinc -c -o start.o start.s
arm-none-linux-gnueabi-gcc -fno-builtin -nostdinc -c -o main.0 main.c
arm-none-linux-gnueabi-ld start.o main.o -Tmap.lds -o uart.elf
arm-none-linux-gnueabi-objcopy -O binary uart.elf uart.bin
arm-none-linux-gnueabi-objdump -D uart.elf > uart.dis
clean:
rm -rf *.bak start.0 main.o uart.elf uart.bin uart.dis
链接脚本:
OUTPUT FORMAT("elf32-littlearm","elf32-littlearm","elf32-littlearm") //指定格式
OUTPUT_ARCH(arm) //指定输出是ARM
ENTRY(_start) //链接的第一条指令的地址
SECTIONS
{
//. 表示当前位置
. = 0x40008000; //指定链接的起始地址
. = ALIGN(4); //对齐
.text: //代码的开始
{
start.o(.text)
*(.text)
}
. = ALIGN(4);
.data: //数据的开始
{
*(.data)
}
. = ALIGN(4);
.bss: //数据段开始
{
*(.bss)
}
}
汇编程序:
.global delayis
.text
.global _start
_start:
b reset
ldr pc,_undefined_instruction
ldr pc,_software_interrupt
ldr pc,_prefetch_abort
ldr pc,_data_abort
ldr pc,_not_used
ldr pc,_irq
ldr pc,_fiq
_undefined_instruction:
.word _undefined_instruction
_software_interrupt:
.word _software_interrupt
_prefetch_abort:
.word _prefetch_abort
_data_abort:
.word _data_abort
_not_used:
.word _not_used
_irq:
.word _irq
_fig:
.word _fig
reset:
ldr r0,=0x40008000 @ 设置异常向量表的启动地址为0x40008000
mcr p15,0,r0,c12,c0,0 @ Vector Base Address Register
init_stack:
ldr r0,stacktop @ get stack top pointer
@ svc mode stack
mov sp,r0
sub r0,#128*4 @ 512 byte for irq mode of stack
@ irq mode stack
msr cpsr,#0xd2
mov sp,r0
sub r0,#128*4
@ fiq mode stack
msr cpsr,#0xd1
mov sp,r0
sub r0,#0
@ abort mode stack
msr cpsr,#0xd7
mov sp,r0
sub r0,#0
@ undefine mode stack
msr cpsr,#0xdb
mov sp,r0
sub r0,#0
@ sys mode and usr mode stack
msr cpsr,#0x10
mov sp,r0 @ 1024 byte for user mode of stack
b main
delayis:
ldr r4,=0x1ffffff
delayis_loop:
sub r4,r4,#1
cmp r4,#0
bne delayis_loop
mov pc,lr
.aliqn 4
@ swi_interrupt handler
stacktop:
.word stack+4*512
.data
stack:
.space 4*512
.end