智能车制作

标题: xs128 串口调试问题 [打印本页]

作者: happy1990now    时间: 2012-2-16 19:04
标题: xs128 串口调试问题
为了便于小车,调试,写了下串口调试程序,现在遇到一个问题,就是通过 串口调试助手 电脑能接收到XS128发过来的信息,但电脑发向xs128的信息,xs128确接受不到,写了一个简单判断的程序,发现单片机没有收到数据,各位麻烦帮忙看看

代码如下:
//初始化SCI以及相应函数
  1. #include "main.h"


  2. void UART_Init (void)
  3. {
  4. //printf("UART_Init\n");

  5. SCI0CR2=0x2c; //enable Receive Full Interrupt,RX enable,Tx enable

  6. SCI0BDH=0x01; //busclk 8MHz,19200bps,SCI0BDL=0x1a
  7. SCI0BDL=0xa0; //SCI0BDL=busclk/(16*SCI0BDL)
  8. //busclk 32MHz, 9600bps,SCI0BDL=0xD0
  9. //115200 bps SCI0BDL=0x11
  10. } // 64M 9600 SCI0BDH=0x01; SCI0BDL=0xA0;

  11. void uart_putchar ( unsigned char c)
  12. {

  13. while(!(SCI0SR1&0x80)) ; //keep waiting when not empty
  14. SCI0DRL=c;
  15. }


  16. void uart_putstr(char ch[])
  17. {
  18. unsigned char ptr=0;
  19. while(ch[ptr]){
  20. uart_putchar((unsigned char)ch[ptr++]);
  21. }
  22. }

  23. unsigned char uart_getchar(void)
  24. {
  25. // printf("uart_getchar\n");

  26. byte res=0;
  27. while(!(SCI0SR1&0x80)) ; //keep waiting when not empty
  28. return (SCI0DRL);

  29. }
复制代码

测试程序:
  1. void main(void)
  2. {
  3. DDRB = 0xff;
  4. PORTB = 0xff;
  5. /*
  6. DDRA = 0x00;
  7. PUCR_PUPAE = 1;
  8. */
  9. DeviceInit();
  10. EnableInterrupts;

  11. while(1)
  12. {

  13. // if(TimeCount[1]==0) { OutPut_Data();;TimeCount[1] = 3000;}
  14. //if(TimeCount[0]==0) { kalman_update();Motor_Regler();TimeCount[0] = 800;}

  15. if (uart_getchar() == 'c')
  16. uart_putstr("Usart Is Working!");

  17. }

  18. }
复制代码


作者: Solemn胜威    时间: 2012-3-6 15:49
能把你这个整个的NRF2401发给我吗?谢谢咯,我的 邮箱是1174063087@qq.com
作者: hhf1100    时间: 2012-3-12 17:21
能给我发一个吗???459067481@qq.com,谢谢
作者: ilyht    时间: 2012-5-26 17:24
Me too!!!
作者: mxj1005071012    时间: 2013-1-3 14:36
我也需要啊  我的串口助手接不到数据 想确定是硬件问题还是软见问题 891876745@qq.com




欢迎光临 智能车制作 (http://dns.znczz.com/) Powered by Discuz! X3.2