我自己写了一段TQ210板子的串口0裸机驱动,但是不知道为什么,PC上可以接受到板子发过来的数据,但是怎么板子怎么都接受不到PC传过去的数据,请问是啥情况?
我自己也试过,非常的确定他就是卡在 while (!(UTRSTAT0 & (1 << 2)));
#define GPC0CON *((volatile unsigned int *)0xE0200060)
#define GPC0DAT *((volatile unsigned int *)0xE0200064)
int main() __attribute__((section(".main")));
int main()
{
unsigned char c;
uart_init();
GPC0CON &= ~(0xFF << 12);
GPC0CON |= 0x11 << 12; // 配置GPC0_3和GPC0_4为输出
GPC0DAT |= (0x3 << 3); // 熄灭LED1和LED2
puts("UART Test in S5PV210");
puts("1.LED1 Toggle");
puts("2.LED2 Toggle");
puts("Please select 1 or 2 to Toggle the LED");
// putchar('1');
while (1)
{
c = getchar(); // 从串口终端获取一个字符
putchar(c); // 回显
putchar('\r');
if (c == '1')
GPC0DAT ^= 1 << 3; // 改变LED1的状态
else if (c == '2')
GPC0DAT ^= 1 << 4; // 改变LED2的状态
}
return 0;
}
#define GPA0CON *((volatile unsigned int *)0xE0200000)
#define ULCON0 *((volatile unsigned int *)0xE2900000)
#define UCON0 *((volatile unsigned int *)0xE2900004)
#define UFCON0 *((volatile unsigned int *)0xE2900008)
#define UTRSTAT0 *((volatile unsigned int *)0xE2900010)
#define UTXH0 *((volatile unsigned int *)0xE2900020)
#define URXH0 *((volatile unsigned int *)0xE2900024)
#define UBRDIV0 *((volatile unsigned int *)0xE2900028)
#define UDIVSLOT0 *((volatile unsigned int *)0xE290002C)
// #define GPA0CON *((volatile unsigned int *)0xE0200000)
// #define ULCON0 *((volatile unsigned int *)0xE2900400)
// #define UCON0 *((volatile unsigned int *)0xE2900404)
// #define UFCON0 *((volatile unsigned int *)0xE2900408)
// #define UTRSTAT0 *((volatile unsigned int *)0xE2900410)
// #define UTXH0 *((volatile unsigned int *)0xE2900420)
// #define URXH0 *((volatile unsigned int *)0xE2900424)
// #define UBRDIV0 *((volatile unsigned int *)0xE2900428)
// #define UDIVSLOT0 *((volatile unsigned int *)0xE290042C)
/* UART0初始化 */
void uart_init()
{
/*
** 配置GPA0_0为UART_0_RXD
** 配置GPA0_1为UART_0_TXD
*/
GPA0CON &= ~0xFF;
GPA0CON |= 0x22;
GPA0CON &= ~(0xFF<<16);
GPA0CON |= (0x22<<16);
/* 8-bits/One stop bit/No parity/Normal mode operation */
ULCON0 = 0x3;
/* Interrupt request or polling mode/Normal transmit/Normal operation/PCLK/*/
UCON0 = 0x5;//1 | (1 << 2) ;//| (1<<5);
/* 静止FIFO */
UFCON0 = 0;
/*
** 波特率计算:115200bps
** PCLK = 66MHz
** DIV_VAL = (66000000/(115200 x 16))-1 = 35.8 - 1 = 34.8
** UBRDIV0 = 34(DIV_VAL的整数部分)
** (num of 1's in UDIVSLOTn)/16 = 0.8
** (num of 1's in UDIVSLOTn) = 12
** UDIVSLOT0 = 0xDDDD (查表)
*/
UBRDIV0 = 34;
UDIVSLOT0 = 0xDDDD;
}
void putchar(unsigned char c);
static void uart_send_byte(unsigned char byte)
{
while (!(UTRSTAT0 & (1 << 2))); /* 等待发送缓冲区为空 */
UTXH0 = byte; /* 发送一字节数据 */
}
static unsigned char uart_recv_byte()
{
while (!(UTRSTAT0 & 1)); /* 等待接收缓冲区有数据可读 */
return URXH0; /* 接收一字节数据 */
}
void putchar(unsigned char c)
{
uart_send_byte(c);
/* 如果只写'\n',只是换行,而不会跳到下一行开头 */
if (c == '\n')
uart_send_byte('\r');
}
unsigned char getchar()
{
unsigned char c;
c = uart_recv_byte();
return c;
}
void puts(char *str)
{
char *p = str;
while (*p)
putchar(*p++);
putchar('\n');
}
|