打印

stm8 串口模拟

[复制链接]
6216|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
两台设备,一台用的是STM8 105C6T6(主机),另一台用的是STM8 105S4T6(从机)。主机用IO模拟串口同步传输(有一位起始位,一位停止位),波特率1200,用的是内部16M晶振。从机用的UART2接收,配置参数如下:    UART2_Init((u32)1200, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART1_SYNCMODE_CLOCK_ENABLE, UART2_MODE_RX_ENABLE);    UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);
用示波器看主机发送的时序正确,如下图:
我用仿真器,一直进不到:UART2_RX_IRQHandler函数中设置的断点,不知道是什么原因呢?
沙发
shoecat|  楼主 | 2011-4-1 19:38 | 只看该作者
我测试发现:用两个都是STM8 105C6T6进行串口通讯正常(非模拟),把同样的程序改个cpu型号烧写到105S4T6上,串口通讯就不正常(表现为不能进入串口中断),难道105S4T6和105C6T6的串口使用方法不一样吗?

使用特权

评论回复
板凳
shoecat|  楼主 | 2011-4-1 19:39 | 只看该作者
我把程序贴出来,大家帮忙看看啊!先谢谢了!
void UART2_Configuration(void)                //uart initial uart初始化
{
    /* Enable general interrupts */        //開中斷
    enableInterrupts();

  
    UART2_DeInit();

       
   
    UART2_Init((u32)1200, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE);


    UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);


}




void main(void)
{
        _asm("sim");
       
        CLK_Init();        //清時鐘





        UART2_Configuration();

        _asm("rim");




       

       
  while (1)        {
                         
        }
}

使用特权

评论回复
地板
shoecat|  楼主 | 2011-4-1 19:40 | 只看该作者
#include "stm8s_it.h"

extern void @near _stext(); /* startup routine */

void @near (* const _vectab[])() =
  {

    (void @near (*)())0x8200,
    _stext,                  /* RESET */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* TRAP - Software interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq0 - External Top Level interrupt (TLI) */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq1 - Auto Wake Up from Halt interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq2 - Clock Controller interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq3 - External interrupt 0 (tim1A) */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq4 - External interrupt 1 (tim1B) */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq5 - External interrupt 2 (tim1C) */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq6 - External interrupt 3 (tim1D) */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq7 - External interrupt 4 (tim1E) */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq8 - CAN Rx interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq9 - CAN Tx/ER/SC interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq10 - SPI End of transfer interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq11 - TIM1 Update/Overflow/Trigger/Break interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq12 - TIM1 Capture/Compare interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq13 - TIM2 Update/Overflow/Break interrupt  */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq14 - TIM2 Capture/Compare interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq15 - TIM3 Update/Overflow/Break interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq16 - TIM3 Capture/Compare interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq17 - UART1 Tx complete interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq18 - UART1 Rx interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq19 - I2C interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq20 - UART2/UART3 Tx interrupt */

    (void @near (*)())0x8200,
    UART2_RX_IRQHandler,   /* irq21 - UART2/UART3 Rx interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq22 - ADC1/ADC2 end of conversion interrupt */

    (void @near (*)())0x8200,
    TIM4_UPD_OVF_IRQHandler,   /* irq23 - TIM4 Update/Overflow interrupt */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq24 - FLASH interrupt */

    (void @near (*)())0x8200,
    TIM4_UPD_OVF_IRQHandler,   /* irq25 - Reserved */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq26 - Reserved */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq27 - Reserved */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq28 - Reserved */

    (void @near (*)())0x8200,
    NonHandledInterrupt,   /* irq29 - Reserved */

  };

使用特权

评论回复
5
shoecat|  楼主 | 2011-4-1 19:40 | 只看该作者
@near @interrupt void UART2_RX_IRQHandler (void)
{
        u8 r2temp1,r2temp2;
       
//        UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);

    /* In order to detect unexpected events during development,
       it is recommended to set a breakpoint on the following instruction.
    */
          /* Read one byte from the receive data register */
       
     RxBuffer[RxCounter++] = (UART2_ReceiveData8());
       
  
    return;
}

使用特权

评论回复
6
nienianhong| | 2014-2-25 21:38 | 只看该作者

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

14

主题

54

帖子

1

粉丝