Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
UART
君正X1000
君正
x1000串口配置的失败问题
发布于 2017-05-19 16:00:03 浏览:2461
订阅该版
使用的是RT-Thread2.1.0版本,X1000芯片。开了三个串口uart0,uart1,uart2,其中uart2为调试串口。初始化后发现除了调试串口uart2寄存器初始化成功,其余两组初始化失败 board.h ```c #define RT_USING_UART2 #define RT_USING_UART1 #define RT_USING_UART3 ``` drv_uart.c ```c void rt_hw_uart_init(void) { struct rt_serial_device *serial; struct jz_uart_s *uart; struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; #ifdef RT_USING_UART1 { static struct rt_serial_device serial1; static struct jz_uart_s uart1; serial = &serial1; uart = &uart1; serial->ops = &_uart_ops; serial->config = config; serial->config.baud_rate = 9600; uart->hw_base = UART1_BASE; uart->irqno = IRQ_UART1; memset(uart->name,0,RT_NAME_MAX); strcpy(uart->name,"ble"); rt_hw_serial_register(serial, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, uart); } #endif #ifdef RT_USING_UART2 { static struct rt_serial_device serial2; static struct jz_uart_s uart2; serial = &serial2; uart = &uart2; serial->ops = &_uart_ops; serial->config = config; serial->config.baud_rate = 115200; uart->hw_base = UART2_BASE; uart->irqno = IRQ_UART2; rt_hw_serial_register(serial, "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, uart); } #endif #ifdef RT_USING_UART3 { static struct rt_serial_device serial3; static struct jz_uart_s uart3; serial = &serial3; uart = &uart3; serial->ops = &_uart_ops; serial->config = config; serial->config.baud_rate = 115200; uart->hw_base = UART0_BASE; uart->irqno = IRQ_UART0; memset(uart->name,0,RT_NAME_MAX); strcpy(uart->name,"uart0"); rt_hw_serial_register(serial, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, uart); } #endif } static rt_err_t uart_configure (struct rt_serial_device *serial, struct serial_configure *cfg) { rt_uint32_t baud_div; struct jz_uart_s * uart; RT_ASSERT(serial != RT_NULL); serial->config = *cfg; uart = serial->parent.user_data; RT_ASSERT(uart != RT_NULL); printf("#name:%s hw_base:%x cfg:%d ",uart->name,uart->hw_base,cfg->baud_rate); /* Init UART Hardware */ UART_IER(uart->hw_base) = 0; /* clear interrupt */ UART_FCR(uart->hw_base) = ~UARTFCR_UUE; /* disable UART unite */ /* Enable UART clock */ /* Set both receiver and transmitter in UART mode (not SIR) */ UART_SIRCR(uart->hw_base) = ~(SIRCR_RSIRE | SIRCR_TSIRE); /* Set databits, stopbits and parity. (8-bit data, 1 stopbit, no parity) */ UART_LCR(uart->hw_base) = UARTLCR_WLEN_8; printf("UART_LCR:%x",UART_LCR(uart->hw_base)); /* set baudrate */ #if defined(RT_USING_JZ4750) || defined(RT_USING_JZ4755) || defined(RT_USING_JZ4760) if(REG_CPM_CPCCR & (1UL << 30)) { /* CPCCR.ECS = 1: clock source is EXCLK/2 */ baud_div = BOARD_EXTAL_CLK / 2 / 16 / cfg->baud_rate; } else #endif { /* CPCCR.ECS = 0: clock source is EXCLK */ baud_div = BOARD_EXTAL_CLK / 16 / cfg->baud_rate; } UART_LCR(uart->hw_base) |= UARTLCR_DLAB; UART_DLHR(uart->hw_base) = (baud_div >> 8) & 0xff; UART_DLLR(uart->hw_base) = baud_div & 0xff; UART_LCR(uart->hw_base) &= ~UARTLCR_DLAB; /* Enable UART unit, enable and clear FIFO */ UART_FCR(uart->hw_base) = UARTFCR_UUE | UARTFCR_FE | UARTFCR_TFLS | UARTFCR_RFLS; UART_SIRCR(uart->hw_base) = SIRCR_RXPL;//个人添加定义问题用 return (RT_EOK); } void put_uart_log(rt_uint32_t base) { printf("UART_RDR:(%x+00) UART_RDR:0x%08x ",base,UART_RDR(base)); printf("UART_DLHR:(%x+00) UART_DLLR:0x%08x ",base,UART_DLLR(base)); printf("UART_DLHR:(%x+04) UART_DLHR:0x%08x ",base,UART_DLHR(base)); printf("UART_IER:(%x+04) UART_IER:0x%08x ",base,UART_IER(base)); printf("UART_ISR:(%x+08) UART_ISR:0x%08x ",base,UART_ISR(base)); printf("UART_LCR:(%x+0c) UART_LCR:0x%08x ",base,UART_LCR(base)); printf("UART_MCR:(%x+10) UART_MCR:0x%08x ",base,UART_MCR(base)); printf("UART_LSR:(%x+14) UART_LSR:0x%08x ",base,UART_LSR(base)); printf("UART_MSR:(%x+18) UART_MSR:0x%08x ",base,UART_MSR(base)); printf("UART_SPR:(%x+1C) UART_SPR:0x%08x ",base,UART_SPR(base)); printf("UART_MCR:(%x+10) UART_MCR:0x%08x ",base,UART_MCR(base)); printf("UART_SIRCR:(%x+20) UART_SIRCR:0x%08x ",base,UART_SIRCR(base)); } ``` main.c ```c int main(int argc, char** argv) { rt_device_t device; rt_err_t result = RT_EOK; int count = 0; device = rt_device_find("uart1"); if(device != RT_NULL) { printf("find uart1 "); rt_device_set_rx_indicate(device,uart_input); if(rt_device_open(device,RT_DEVICE_OFLAG_RDWR|RT_DEVICE_FLAG_INT_RX) == RT_EOK) { printf("open uart1 ok "); //rt_size_t size = rt_device_write(device,0,"12345678",8); //printf("write size:%d ",size); printf("write size "); } } else printf("cannot find uart1 "); put_uart_log(UART0_BASE); printf("################## "); put_uart_log(UART1_BASE); printf("################## "); put_uart_log(UART2_BASE); printf("################## "); } ``` 打印信息如下: ``` UART_RDR:(b0030000+00) UART_RDR:0x00000000 UART_DLHR:(b0030000+00) UART_DLLR:0x00000000 UART_DLHR:(b0030000+04) UART_DLHR:0x00000000 UART_IER:(b0030000+04) UART_IER:0x00000000 UART_ISR:(b0030000+08) UART_ISR:0x00000000 UART_LCR:(b0030000+0c) UART_LCR:0x00000000 UART_MCR:(b0030000+10) UART_MCR:0x00000000 UART_LSR:(b0030000+14) UART_LSR:0x00000000 UART_MSR:(b0030000+18) UART_MSR:0x00000000 UART_SPR:(b0030000+1C) UART_SPR:0x00000000 UART_MCR:(b0030000+10) UART_MCR:0x00000000 UART_SIRCR:(b0030000+20) UART_SIRCR:0x00000000 ################## UART_RDR:(b0031000+00) UART_RDR:0x00000000 UART_DLHR:(b0031000+00) UART_DLLR:0x00000000 UART_DLHR:(b0031000+04) UART_DLHR:0x00000000 UART_IER:(b0031000+04) UART_IER:0x00000000 UART_ISR:(b0031000+08) UART_ISR:0x00000000 UART_LCR:(b0031000+0c) UART_LCR:0x00000000 UART_MCR:(b0031000+10) UART_MCR:0x00000000 UART_LSR:(b0031000+14) UART_LSR:0x00000000 UART_MSR:(b0031000+18) UART_MSR:0x00000000 UART_SPR:(b0031000+1C) UART_SPR:0x00000000 UART_MCR:(b0031000+10) UART_MCR:0x00000000 UART_SIRCR:(b0031000+20) UART_SIRCR:0x00000000 ################## UART_RDR:(b0032000+00) UART_RDR:0x0000000d UART_DLHR:(b0032000+00) UART_DLLR:0x0000000d UART_DLHR:(b0032000+04) UART_DLHR:0x00000011 UART_IER:(b0032000+04) UART_IER:0x00000011 UART_ISR:(b0032000+08) UART_ISR:0x000000c1 UART_LCR:(b0032000+0c) UART_LCR:0x00000003 UART_MCR:(b0032000+10) UART_MCR:0x00000000 UART_LSR:(b0032000+14) UART_LSR:0x00000020 UART_MSR:(b0032000+18) UART_MSR:0x00000000 UART_SPR:(b0032000+1C) UART_SPR:0x00000000 UART_MCR:(b0032000+10) UART_MCR:0x00000000 UART_SIRCR:(b0032000+20) UART_SIRCR:0x00000010 ################## ``` 有打印信息发现除了调试串口寄存器配置成功,其余两个串口寄存器配置失败,大家有什么好的建议吗?
查看更多
3
个回答
默认排序
按发布时间排序
cuijianjoy
2017-05-19
这家伙很懒,什么也没写!
和时钟有关 谢谢!
yytyu
2017-11-09
这家伙很懒,什么也没写!
请下问是怎样配置的?
撰写答案
登录
注册新账号
关注者
0
被浏览
2.5k
关于作者
cuijianjoy
这家伙很懒,什么也没写!
提问
2
回答
2
被采纳
0
关注TA
发私信
相关问题
1
rt thread 2.0.2 usart 接收缓存问题
2
关于STM32串口通信的问题
3
STM32F1+RTT串口接收终端数据丢失问题
4
UART TX丢数据?
5
RTT打开串口的时候如何自定义波特率呢?
6
STM32F4的USART数据接收问题
7
串口1234使用问题
8
串口接收回调函数
9
LPC18xx UART问题讨论
10
如何用串口输出一个字符
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
13
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
本月文章贡献
程序员阿伟
7
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
3
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部