你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM8做有通讯协议的通讯程序碰到的问题,请高手指点问题出在哪里?

[复制链接]
getion-110578 提问时间:2009-10-30 15:48 /
STM8通讯的问题
我想用STM8做有通讯协议的通讯程序,,我是用接收数据满进行中断接收,然后将接收到的数据回发,
现在根据下面的程序,发送没有问题,发送程序我没有贴出来,
 
但就是接收不行,我在看变量与寄存器时,发现发送的第一个数据到了数据寄存器内,就是没有进入到中断程序
因为STM8初学,所以不知道是中断出问题,还是中断内的程序出问题,请高手指点一下,在下将万分感谢
 
 
这段是设置文件
void main(void)
{
    unsigned int i,n;
    unsigned char counter;
    /*High speed internal clock prescaler: 1*/
    CLK_CKDIVR = 0x00;
    LINUART_CR2 = 0x00;    //disable Tx & Rx
    /* LINUART configured as follow:
          - BaudRate = 115200 baud 
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - Receive and transmit enabled
          - LINUART Clock disabled
    */
    /* Configure UART1 */
  
    LINUART_CR1  = 0x00;
    LINUART_CR3  = 0x00;
    LINUART_BRR2 = 0x0B;
    LINUART_BRR1 = 0x08;
  ITC_SPR6  =    0XF3;
    LINUART_CR2  = 0x2C;     //允许接收与发送 
  //LINUART_SR   = 0X00;
 
 
下面是中断文件中的中断程序
/* BASIC INTERRUPT VECTOR TABLE FOR STM8 devices
 * Copyright (c) 2007 STMicroelectronics
 */
#include "stm8s207r.h"          /* Registers and memory mapping file. */
#include "stdio.h"
extern char Uart_Rx_Data[22];
extern unsigned char Uart_Count;
extern unsigned char RxBuffer;

#define Start_Command0  0xAA
#define Start_Command1  0x55
//数据区
#define Over_Command0   0xFF
#define Over_Command1   0xFF
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
    unsigned char interrupt_instruction;
    interrupt_handler_t interrupt_handler;
};
@far @interrupt void NonHandledInterrupt (void)
{
    /* in order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction
    */
    return;
}
@far @interrupt void LINUART_RX_IRQHandler (void)
{
   char U;
  U=0X11;                                                            //是用来看是否进入中断的变量           
   while (!(LINUART_SR & 0x20))                    //是接收中断
   {
   //LINUART_SR = 0;              //清接收标志位
  RxBuffer=LINUART_DR ;              //读出数据,并清接收  标志位
  }
   if(Uart_Count==0)                 //根据通信协议字头第易   字节 0xAA
    {
  // RxBuffer=Start_Command0;
  if(RxBuffer!=Start_Command0)
       {
        Uart_Count = 0;
    return;
          }
       else
   { Uart_Rx_Data[Uart_Count] = RxBuffer;
     Uart_Count++;
    
      } 
    }
   if(Uart_Count==1)     //根据通信协议字头第二字节为0X55                           
     {
  //RxBuffer=Start_Command1; 
   if(RxBuffer!=Start_Command1)
        {
          Uart_Count = 0;
     return;
           }
   else
   { Uart_Rx_Data[Uart_Count] = RxBuffer;
     Uart_Count++;
    
      }
      } 
   RxBuffer=03;
    Uart_Rx_Data[Uart_Count] = RxBuffer;
      Uart_Count++;
 
  if (Uart_Count==20)
     {
  //  RxBuffer=Over_Command0;
    if(RxBuffer!=Over_Command0)
   { Uart_Count = 0;
     return;
    }
       else
   { Uart_Rx_Data[Uart_Count] = RxBuffer;
    // Uart_Count++;
    
      }
      }
    if (Uart_Count==21)
     {
  //  RxBuffer=Over_Command1;
     if(RxBuffer!=Over_Command1)
   { Uart_Count = 0;
     return;
    }
    else
   {Uart_Rx_Data[Uart_Count] = RxBuffer;
   Uart_Count = 0;}
      }
   return;
}
 

extern void _stext();     /* startup routine */
struct interrupt_vector const _vectab[] = {
    {0x82, (interrupt_handler_t)_stext}, /* reset */
    {0x82, NonHandledInterrupt}, /* trap  */
    {0x82, NonHandledInterrupt}, /* irq0  */
    {0x82, NonHandledInterrupt}, /* irq1  */
    {0x82, NonHandledInterrupt}, /* irq2  */
    {0x82, NonHandledInterrupt}, /* irq3  */
    {0x82, NonHandledInterrupt}, /* irq4  */
    {0x82, NonHandledInterrupt}, /* irq5  */
    {0x82, NonHandledInterrupt}, /* irq6  */
    {0x82, NonHandledInterrupt}, /* irq7  */
    {0x82, NonHandledInterrupt}, /* irq8  */
    {0x82, NonHandledInterrupt}, /* irq9  */
    {0x82, NonHandledInterrupt}, /* irq10 */
    {0x82, NonHandledInterrupt}, /* irq11 */
    {0x82, NonHandledInterrupt}, /* irq12 */
    {0x82, NonHandledInterrupt}, /* irq13 */
    {0x82, NonHandledInterrupt}, /* irq14 */
    {0x82, NonHandledInterrupt}, /* irq15 */
    {0x82, NonHandledInterrupt}, /* irq16 */
    {0x82, NonHandledInterrupt}, /* irq17 */
    {0x82, NonHandledInterrupt}, /* irq18 */
    {0x82, NonHandledInterrupt}, /* irq19 */
    {0x82, NonHandledInterrupt}, /* irq20 */
    {0x82, LINUART_RX_IRQHandler}, /* irq21 */
    {0x82, NonHandledInterrupt}, /* irq22 */
    {0x82, NonHandledInterrupt}, /* irq23 */
    {0x82, NonHandledInterrupt}, /* irq24 */
    {0x82, NonHandledInterrupt}, /* irq25 */
    {0x82, NonHandledInterrupt}, /* irq26 */
    {0x82, NonHandledInterrupt}, /* irq27 */
    {0x82, NonHandledInterrupt}, /* irq28 */
    {0x82, NonHandledInterrupt}, /* irq29 */
};
 
收藏 评论0 发布时间:2009-10-30 15:48

举报

0个回答
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版