打印
[STM8]

STM8A关于串口问题???

[复制链接]
3268|11
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
win2000_li|  楼主 | 2009-7-6 17:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
当我初始化串口时,因为对库函数不熟,没有找到

对CR2操作的函数或方式,只有这样USART->CR2 |= 0xAC;

但是我在寄存器窗口看,没有变化啊!!!

请老师指点一下。


void UartInit(void)
{
    // Initial RST stat
    USART_DeInit();
    
    USART_Cmd(ENABLE);
    
    // 9600,1,0  RX TX Interrupt Enable
    USART_Init((u32)9600,  USART_WORDLENGTH_8D, USART_STOPBITS_1, USART_PARITY_NO, USART_SYNCMODE_CLOCK_DISABLE, (USART_MODE_TX_DISABLE | USART_MODE_RX_ENABLE));
    
    USART->CR2 |= 0xAC;

    // Enable the USART Receive interrupt: this interrupt is generated when the    USART receive data register is not empty 
    USART_ITConfig(USART_IT_RXNE_OR, ENABLE);
    
}
沙发
win2000_li|  楼主 | 2009-7-7 11:18 | 只看该作者

顶一个!!!

自已顶!

使用特权

评论回复
板凳
wolver| | 2009-7-7 12:29 | 只看该作者

STM8的库函数我从来没用过,给你个查询试的代码

#define USART_INIT()        
{    
  _asm("ld a, _USART_SR ");    
  _asm("ld a, _USART_DR ");    
  USART_BRR2 = 0x00;        
  USART_BRR1 = 0x00;        
  USART_CR1 = 0x00;            
  USART_CR2 = 0x00;            
  USART_CR3 = 0x00;            
  USART_CR4 = 0x00;            
  USART_CR5 = 0x00;            
  USART_GTR = 0x00;            
  USART_PSCR = 0x00;        
                                                
  USART_BRR2 = (u8)(((Fosc/(16 * BAUD)) >> 8)  & 0xFF);    
  USART_BRR1 = (u8)((Fosc/(16 * BAUD)) & 0xFF);                    
                                            
  USART_CR2 |= BIT(3);    
}

void usart_putchar(u8 c)
{
  while(!(USART_SR & BIT(7)))
  {
    IWDG_REFRESH();
  }
    USART_DR = c;
    
  return;
}

使用特权

评论回复
地板
win2000_li|  楼主 | 2009-7-7 13:54 | 只看该作者

谢谢wolver!!

以下是我的程序,不知道为什么就是发不出来啊!!

请老师指点一下,看一看是哪里的问题。。。




@near @interrupt void USART_TX_IRQHandler (void)
{
    static INT8U TxCnt = SetZero;
    
    /* Write one byte to the transmit data register */
     USART_SendData8(TxBuf[TxCnt++]);
  
    if (TxCnt == TxLen)
    {
        /* Disable the USART Transmit interrupt */
        USART_ITConfig(USART_IT_TXE, DISABLE);
        TxCnt = ClrZero;
    }
    return;
}

void UartInit(void)
{
    // Initial RST stat
    USART_DeInit();
    
    USART_Cmd(ENABLE);
    
    // 9600,1,0  RX TX Interrupt Enable
    USART_Init((u32)9600,  USART_WORDLENGTH_8D, USART_STOPBITS_1, USART_PARITY_NO, USART_SYNCMODE_CLOCK_DISABLE, USART_MODE_TXRX_ENABLE);
    
    // Enable the USART Receive interrupt: this interrupt is generated when the    USART receive data register is not empty 
    USART_ITConfig(USART_IT_RXNE_OR, ENABLE);
}

void SendNumChar(u8 *SendBufAddr, u8 Num)
{    
    memcpy(TxBuf, SendBufAddr, Num);
    TxLen = Num;
    USART_ITConfig(USART_IT_TXE, ENABLE);
}

使用特权

评论回复
5
chineser| | 2009-7-7 14:53 | 只看该作者

不有例程吗

使用特权

评论回复
6
win2000_li|  楼主 | 2009-7-7 15:09 | 只看该作者

我是按例子做的啊!!!

但是不对头啊!!!!!!

使用特权

评论回复
7
win2000_li|  楼主 | 2009-7-7 15:17 | 只看该作者

这是例子啊

examples/USART/USART_HyperTerminal_Interrupt/main.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file USART_HyperTerminal_Interruptmain.c
00004   * @brief This file contains the main function for usart using interrupts in communication example.
00005   * @author STMicroelectronics - APG Application Team
00006   * @version V1.0.1
00007   * @date 09/22/2008
00008   ******************************************************************************
00009   *
00010   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00011   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00012   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00013   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00014   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00015   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00016   *
00017   * <h2><center>© COPYRIGHT 2008 STMicroelectronics</center></h2>
00018   * @image html **.bmp
00019   ******************************************************************************
00020   */
00021 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm8a_lib.h"
00024 
00025 /**
00026   * @addtogroup USART_HyperTerminal_Interrupt
00027   * @{
00028   */
00029 /* Private typedef -----------------------------------------------------------*/
00030 /* Private define ------------------------------------------------------------*/
00031 /* Private macro -------------------------------------------------------------*/
00032 /* Private variables ---------------------------------------------------------*/
00033 /* Private variables ---------------------------------------------------------*/
00034 /* Private function prototypes -----------------------------------------------*/
00035 /* Private functions ---------------------------------------------------------*/
00036 /**
00037   * @brief Validation firmware main entry point.
00038   * @par Parameters:
00039   * None
00040   * @retval void None
00041   * @par Required preconditions:
00042   * None
00043   * @par Library functions called:
00044   * - USART_DeInit()
00045   * - USART_Init()
00046         * - USART_Cmd()
00047   * - USART_ITConfig()
00048         * - CLK_HSIPrescalerConfig()
00049   */
00050 void main(void)
00051 {
00052     /* Enable general interrupts */
00053     enableInterrupts();
00054 
00055     /*High speed internal clock prescaler: 1*/
00056     CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
00057 
00058     USART_DeInit();
00059     /* USART configuration ------------------------------------------------------*/
00060     /* USART configured as follow:
00061                 - BaudRate = 9600 baud  
00062           - Word Length = 8 Bits
00063           - One Stop Bit
00064           - Odd parity
00065           - Receive and transmit enabled
00066           - USART Clock disabled
00067     */
00068     /* Configure the USART */
00069     USART_Init((u32)9600, USART_WORDLENGTH_8D, USART_STOPBITS_1, USART_PARITY_ODD, USART_SYNCMODE_CLOCK_DISABLE, USART_MODE_TXRX_ENABLE);
00070 
00071     /* Enable the USART Transmit interrupt: this interrupt is generated when the
00072        USART transmit data register is empty */
00073     USART_ITConfig(USART_IT_TXE, ENABLE);
00074     /* Enable the USART Receive interrupt: this interrupt is generated when the
00075        USART receive data register is not empty */
00076     USART_ITConfig(USART_IT_RXNE_OR, ENABLE);
00077 
00078     while (1);
00079 }
00080 
00081 /**
00082   * @brief Reports the name of the source file and the source line number where
00083   * the assert error has occurred.
00084   * User can add his own implementation to report the file name and line number.
00085   * ex: printf("Wrong parameters value: file %s on line %d ", file, line)
00086   * @retval void None
00087   * @par Required preconditions:
00088   * None
00089   * @par Called functions:
00090   * None
00091   */
00092 #ifdef FULL_ASSERT
00093 void assert_failed(u8 *file, u16 line)
00094 #else
00095 void assert_failed(void)
00096 #endif
00097 {
00098     /* Add your own code to manage an assert error */
00099     /* Infinite loop */
00100     while (1)
00101     {
00102     }
00103 }
00104 
00105 /**
00106   * @}
00107   */
00108 
00109 /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/

使用特权

评论回复
8
win2000_li|  楼主 | 2009-7-7 15:47 | 只看该作者

原来是这样啊!!!

为什么我设置UART,反而设置成LIN去了??

怎么才能区别是UART,还是LIN呢????

使用特权

评论回复
9
win2000_li|  楼主 | 2009-7-7 17:57 | 只看该作者

自已顶

自已顶

使用特权

评论回复
10
win2000_li|  楼主 | 2009-7-8 08:33 | 只看该作者

顶一个!!!

没有人理我啊!!!

使用特权

评论回复
11
banrn| | 2009-10-28 12:05 | 只看该作者
为什么我设置UART,反而设置成LIN去了??怎么才能区别是UART,还是LIN呢????
win2000_li 发表于 2009-7-7 15:47


中断向量可能错了。

STM8A库里的中断向量表是有问题的。

使用特权

评论回复
12
eric_123| | 2009-10-28 15:50 | 只看该作者
寄存器映射有问题,看看汇编是设到什么地址上了

使用特权

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

本版积分规则

142

主题

718

帖子

1

粉丝