spkk 发表于 2013-3-28 18:40:35

TQ2440裸机串口问题,请大神帮忙

本帖最后由 spkk 于 2013-4-10 16:00 编辑

老师给布置的任务,要求是norflash上一句代码都不能有,从启动开始写起,实现串口收到一个数据后再发回一个数据,现在问题是收到的和发送的都是乱码,不知道是启动时初始化有问题还是怎么,AXD+jlink调试时发现0x50000020和0x50000024处的数据都没有对,代码如下,希望大神能帮我分析下大概是怎么回事。。。boot.s:启动初始化的代码
;***************work mode defines***********************
USERMODE      EQU      0x10
FIQMODE                EQU      0x11
IRQMODE                EQU      0x12
SVCMODE                EQU      0x13
ABORTMODE      EQU      0x17
UNDEFMODE      EQU      0x1b
SYSMODE                EQU      0x1f
;**************work mode defines end********************
;**************INTs defines*****************************
NOINT                EQU      0xc0
SUBINTDIS      EQU      0x4A00001C
IRQDIS                EQU      0x80
FIQDIS                EQU      0x40
;*************INTs defines end**************************
;*******************hardware defines********************
WTCON                EQU      0x53000000
LOCKTIME      EQU      0x4C000000
CLKDIV                EQU      0x4C000014
UPLLCON                EQU      0x4C000008
MPLLCON                EQU      0x4C000004

M_MDIV                EQU      92
M_PDIV                EQU      1
M_SDIV                EQU      1      
U_PDIV                EQU      2      
U_MDIV                EQU      56
U_SDIV                EQU      2
;******************hardware defines end*****************
;------------------Stack Addr Define--------------------
_STACKBASEADDR      EQU      0x33ff8000
StackUse EQU (_STACKBASEADDR-0x3800)
StackSvc      EQU      (_STACKBASEADDR-0x2800)
StackUnd      EQU      (_STACKBASEADDR-0x2400)
StackAbt      EQU      (_STACKBASEADDR-0x2000)
StackIRQ      EQU      (_STACKBASEADDR-0x1000)
StackFIQ      EQU      (_STACKBASEADDR-0x0000)
;-------------Stack Addr Define Ends--------------------
IMPORT IRQHandle
                                       ;this is used by asm
IMPORT      FIQ_Exception      ;the FIQ process func,used by asm
IMPORT Main
EXPORT HandlerSWI      ;this is used by c
GET inc/memdef.inc
CODE32
AREA Boot,CODE,READONLY
ENTRY
Vectors
B      ResetInit      ;reset int.
B      HandlerUndef      ;the undefined int
      B      HandlerSWI      ;software int
B      HandlerPabort      ;int for get command error,use for MMU
      B      HandlerDabort      ;int for get data error,use for MMU
      NOP                ;reserved
      ;B      HandlerIRQ      ;int
      B      IRQHandle
      B      HandlerFIQ      ;fast int

main.c 串口初始化以及发送接收//***************GPIO Defines******************
#define      GPBCON                (*(volatile      unsigned long*)0x56000010)
#define      GPBIOCON      0x00015400
#define      GPBDAT                (*(volatile      unsigned long*)0x56000014)      

#define rGPHCON    (*(volatile unsigned long*)0x56000070)      //Port H control
#define rGPHDAT    (*(volatile unsigned long*)0x56000074)      //Port H data
#define rGPHUP   (*(volatile unsigned long*)0x56000078)      //Pull-up control H

//****************GPIO Defines Ends***********

//**************UART Defines*****************
//uart line control
#define      ULCON0      (*(volatile unsigned *)0x50000000)
//uart control
#define UCON0      (*(volatile unsigned *)0x50000004)
//uart baud rate divisor
#define      UBRDIV0      (*(volatile unsigned *)0x50000028)
//uart fifo control
#define      UFCON0      (*(volatile      unsigned *)0x50000008)
//uart modem control
#define UMCON0      (*(volatile unsigned *)0x5000000C)
//uart TX/RX status control
#define UTRSTAT0      (*(volatile unsigned *)0x50000010)
//uart error status control
#define UERSTAT0                (*(volatile unsigned *)0x50000014)
//uart FIFO status
#define      UFSRAT0                (*(volatile unsigned *)0x50000018)
//uart modem status
#define      UMSTAT0                (*(volatile unsigned *)0x5000001C)
//uart transmit buffer reg.little endian
#define      UTXH0      (*(volatile unsigned char*)0x50000020)
//uart receive buffer reg.little endian
#define URXH0      (*(volatile unsigned char*)0x50000024)
//TXD0 Ready,means can sent a char out
//#define TXD0READY      (1<<2)
#define TXD0READY      0x2
//RXD0 Ready means can receive a char
//#define      RXD0READY      (1)
#define      RXD0READY      0x1

//************UART Defines End***************

unsigned int PCLK;      
int fireLED(int led);
int killAllLED(void);
void delay(int ms);
void uartInit(void);
void uartPutchar(unsigned char c);
unsigned char uartGetchar(void);
void Main(void){
      //GPBCON = 0x00001000;//2 digit a bit,the led is from gpb5 to gpb8
      //GPBDAT = 0x00000000;
      unsigned char tmp = 0;
      int foo,bar;
      fireLED(4);
      tmp = 'b';
      uartInit();
      uartPutchar(tmp);
      
      while(1){
      
                tmp = uartGetchar();
                for(foo = 0;foo<1000;foo++)
                {
                        for(bar = 0;bar<1000;bar++);
                }
                if(/*(int)tmp>0*/1){
                        unsigned char forDebug = tmp;
                        uartPutchar(forDebug);
                }
      }
      return;

}
int fireLED(int led){
      
      int foo;
      unsigned long tmp = 0x100;
      for(foo = led;foo > 0;foo--){
                tmp*=4;
      }
      GPBCON = tmp;
      GPBDAT = 0x00000000;
      return 1;
}
int killAllLED(){
      GPBDAT = 0xFFF;
      return 0;
}
void uartInit(void){
      int pclk = 50000000;//50MHz
      int buat = 115200;
      //BAUD RATE equation:
      //UBRDIV0 = (int)(pclk/(buat*16))-1;
      //see chapter 11 in datashit
      rGPHCON      |= 0xa0;//GPH2,GPH3 set to TXD0 and RXD0
                                        //10100000b=0xa0
                                        //see the chapter9 in datashit
      rGPHUP =      0x0;/* 0x0c;*/ //enable pull up reg
      
      ULCON0 = 0x03;      //8bit
      //UCON0 = 0x05;
         //when the TX is empty or the FIFO stacks is reach the deep the call the INT
      UFCON0 = 0x0;      //disable FIFO
      UMCON0 = 0x0;      
      UBRDIV0 = (int)((pclk/(buat*16))-1);//set the BAUD RATE
      //UTRSTAT0 = 0x0;
      URXH0 =0;
    UTXH0 =0;
}

void uartPutchar(unsigned char c){
      while(!(UTRSTAT0&TXD0READY));//wait the buffer empty
      //killAllLED();
      fireLED(1);
      UTXH0 = c;      
}
unsigned char uartGetchar(void){
      while(!(UTRSTAT0&RXD0READY));//wait the buffer is full
      fireLED(3);
      return URXH0;
}

亚瑟王 发表于 2013-3-29 17:56:32

亲,烧写TQ2440_Test然后看串口部分初始化对不对?

spkk 发表于 2013-3-30 14:22:44

亚瑟王 发表于 2013-3-29 17:56 static/image/common/back.gif
亲,烧写TQ2440_Test然后看串口部分初始化对不对?

谢谢版主!昨天上午就解决了,是锁相环的问题,MPLL频率没有配置正确,导致串口的波特率没对,所以发送接受都是乱码。。。。。

亚瑟王 发表于 2013-4-1 10:49:38

spkk 发表于 2013-3-30 14:22 static/image/common/back.gif
谢谢版主!昨天上午就解决了,是锁相环的问题,MPLL频率没有配置正确,导致串口的波特率没对,所以发送接 ...

亲,问题解决了,请把帖子类型改为“已解决”。(方法请参考:http://www.armbbs.net/forum.php?mod=viewthread&tid=15200)。
页: [1]
查看完整版本: TQ2440裸机串口问题,请大神帮忙