3014|1

3

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

使用keil'写UART驱动发送的数据只有00? [复制链接]

keil UART驱动代码如下:
#include "UART.h"
#include

#define GPIO_PORTB_AFSEL_R                        (*((volatile unsigned long *)0x40005420))
#define GPIO_PORTB_AMSEL_R                        (*((volatile unsigned long *)0x40005528))
#define GPIO_PORTB_PCTL_R                                (*((volatile unsigned long *)0x4000552C))
#define GPIO_PORTB_DEN_R                                (*((volatile unsigned long *)0x4000551C))
       
#define UART1_DR_R              (*((volatile unsigned long *)0x4000D000))
#define UART1_FR_R              (*((volatile unsigned long *)0x4000D018))
#define UART1_IBRD_R            (*((volatile unsigned long *)0x4000D024))
#define UART1_FBRD_R            (*((volatile unsigned long *)0x4000D028))
#define UART1_LCRH_R            (*((volatile unsigned long *)0x4000D02C))
#define UART1_CTL_R             (*((volatile unsigned long *)0x4000D030))
#define UART_FR_TXFF            0x00000020  // UART Transmit FIFO Full
#define UART_FR_RXFE            0x00000010  // UART Receive FIFO Empty
#define UART_LCRH_WLEN_8        0x00000060  // 8 bit word length
#define UART_LCRH_FEN           0x00000010  // UART Enable FIFOs
#define UART_CTL_UARTEN         0x00000001  // UART Enable
#define SYSCTL_RCGC1_R          (*((volatile unsigned long *)0x400FE104))
#define SYSCTL_RCGC2_R          (*((volatile unsigned long *)0x400FE108))
#define SYSCTL_RCGC1_UART1      0x00000002  // UART0 Clock Gating Control
#define SYSCTL_RCGC2_GPIOB      0x00000002  // port B Clock Gating Control


//------------UART_Init------------
// Wait for new serial port input
// Initialize the UART for 115,200 baud rate (assuming 80 MHz UART clock),
// 8 bit word length, no parity bits, one stop bit, FIFOs enabled
// Input: none
// Output: none
void UART_Init(void){
       
        //GPIOPinConfigure(GPIO_PB0_U1RX);   

        //GPIOPinConfigure(GPIO_PB1_U1TX);
        SYSCTL_RCGC1_R |= SYSCTL_RCGC1_UART1; // activate UART1
  SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOB; // activate port B
       
  UART1_CTL_R &= ~UART_CTL_UARTEN;      // disable UART
  UART1_IBRD_R = 43;                    // IBRD = int(80,000,000 / (16 * 115200)) = int(43.402778)
  UART1_FBRD_R = 26;                    // FBRD = round(0.402778 * 64) = 26
                                        // 8 bit word length (no parity bits, one stop bit, FIFOs)
  UART1_LCRH_R = (UART_LCRH_WLEN_8|UART_LCRH_FEN);
  UART1_CTL_R |= UART_CTL_UARTEN;       // enable UART

        GPIO_PORTB_AFSEL_R |= 0x03;           // enable alt funct on PB1-0
  GPIO_PORTB_DEN_R |= 0x03;             // enable digital I/O on PB1-0
                                        // configure PB1-0 as UART
        GPIO_PORTB_PCTL_R = (GPIO_PORTB_PCTL_R&0xFFFFFF00)+0x00000011;
        GPIO_PORTB_AMSEL_R &= ~0x03;          // disable analog functionality on PB
       
}


//------------UART_InChar------------
// Wait for new serial port input
// Input: none
// Output: ASCII code for key typed
unsigned char UART_InChar(void){
// while((UART1_FR_R&UART_FR_RXFE) != 0);
  //return((unsigned char)(UART1_DR_R&0xFF));
       
        int ret;
        char rdata;
       
        while((UART1_FR_R & 0x10)!=0);
       
        ret = UART1_DR_R;
        if(!(ret & 0xF00)){
                rdata = (char)(UART1_DR_R & 0xFF);
        }
        return rdata;
}
//------------UART_OutChar------------
// Output 8-bit to serial port
// Input: letter is an 8-bit ASCII character to be transferred
// Output: none
void UART_OutChar(unsigned char data){
  while((UART1_FR_R&UART_FR_TXFF) != 0);
  UART1_DR_R = data;
}
// Print a character to UART0.





主函数:

#include    // standard C library
#include "UART.h"    // functions to implment input/output
#include "TExaS.h"   // Lab grader functions


void        UART_Init(void);


int main (void) {

        UART_Init();

        while(1)
        {
                UART_OutChar('a');
        }
       
        return 0;
       
}

请问是我的驱动设置有问题还是其他问题,怎么解决?


 
点赞 关注

回复
举报

3

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
求各位大神不吝赐教
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表