串口调试时没有接收数据
请教问题:在用串口调试助手调试下面的程序时,发送“A”或者“B”,都没有接收到数据,请问是哪里出了问题呢?谢谢
#include "Led.h"
#include "uart.h"
unsigned char cmd;
void main(void)
{
Led_Init();
Uart_Init();
while(1)
{
switch(cmd)
{
case 'A':
cmd=0;
Uart_Print("LED1_ON",7);
Led1_On();
break;
case 'B':
cmd=0;
Uart_Print("Led1_OFF",8);
Led1_Off();
break;
}
}
}
#pragma vector=URX0_VECTOR
__interrupt void URX0_ISR(void)
{
cmd=U0DBUF;
URX0IF=0;
}
你助手软件接收的波特率和串口有无选对?需要两边Baud rate一样才可以。
选对了啊 都是19200
既然是两边都对的话,那么你看下串口助手,应该有正确的数据才对。
可是串口助手上面显示没有信号,是什么原因呢?
你只给出单纯代码,你有无排除是否其他原因导致?试过两台电脑的串口调试了吗?
另外你的串口如何接到cc1110去?电脑设备管理器显示的是那个设备?
可以先将电脑串口的RXD和DXD短接,测试串口助手驱动有没有打开;
UART要接收使能,并且开启UART中断和EA;
单步调试一下,看一下自己设置的UART寄存器有没有生效;
注意UCR_FLUSH的使用。
帮我看下是不是这个程序的问题,谢谢。(我总感觉Uart.h有点问题)
main.c:
#include "Led.h"
#include "uart.h"
unsigned char cmd;
void main(void)
{
Led_Init();
Uart_Init();
while(1)
{
switch(cmd)
{
case 'A':
cmd=0;
Uart_Print("LED1_ON",7);
Led1_On();
break;
case 'B':
cmd=0;
Uart_Print("Led1_OFF",8);
Led1_Off();
break;
}
}
}
#pragma vector=URX0_VECTOR
__interrupt void URX0_ISR(void)
{
cmd=U0DBUF;
URX0IF=0;
}
Uart.c:
#include<ioCC2540.h>
#include "uart.h"
void Uart_Init(void)
{
CLKCONCMD&=~(1<<6);
while(CLKCONSTA&(1<<6));
CLKCONCMD&=~((1<<6)|(7<<0));
PERCFG=0x00;
P0SEL|=(0xf<<2);
P2DIR&=~(3<<6);
U0CSR|=1<<7;
U0GCR=9;
U0BAUD=59;
UTX0IF=0;
U0CSR|=1<<6;
URX0IF=1;
EA=1;
}
void Uart_Print(char *p,int len)
{
unsigned int i;
for(i=0;i<len;i++)
{
U0DBUF=*p++;
while(!UTX0IF);
UTX0IF=0;
}
U0DBUF=0x0A;
while(!UTX0IF);
UTX0IF=0;
}
Uart.h:
#ifndef __UART_H_
#define __UART_H_
extern void Uart_Init(void);
extern void Uart_Print(char *p,int len);
#endif
Led.c:
#include <ioCC2540.h>
#include "led.h"
void Led_Init(void)
{
P1SEL &= ~ (1<<0);
P1DIR |=(1<<0);
LED1 =0;
}
void Delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<10000;j++);
}
Led.h:
#ifndef __LED_H__
#define __LED_H__
#include <ioCC2540.h>
#define LED1 P1_0
#define Led1_On() LED1=1;
#define Led1_Off() LED1=0;
extern void Led_Init(void);
extern void Delay(unsigned int time);
#endif