4173|11

79

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

STM8A关于串口问题??? [复制链接]

当我初始化串口时,因为对库函数不熟,没有找到

对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);
    
}
此帖出自stm32/stm8论坛

最新回复

                                 寄存器映射有问题,看看汇编是设到什么地址上了  详情 回复 发表于 2009-10-28 15:50
点赞 关注
 

回复
举报

65

帖子

0

TA的资源

一粒金砂(初级)

沙发
 

顶一个!!!

                                 自已顶!
此帖出自stm32/stm8论坛
 
 

回复

78

帖子

0

TA的资源

一粒金砂(初级)

板凳
 

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;
}
此帖出自stm32/stm8论坛
 
 

回复

84

帖子

0

TA的资源

一粒金砂(初级)

4
 

谢谢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);
}

此帖出自stm32/stm8论坛
 
 
 

回复

64

帖子

0

TA的资源

一粒金砂(初级)

5
 

不有例程吗

                                  
此帖出自stm32/stm8论坛
 
 
 

回复

74

帖子

0

TA的资源

一粒金砂(初级)

6
 

我是按例子做的啊!!!

                                 但是不对头啊!!!!!!
此帖出自stm32/stm8论坛
 
 
 

回复

87

帖子

0

TA的资源

一粒金砂(初级)

7
 

这是例子啊

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 logo.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****/

此帖出自stm32/stm8论坛
 
 
 

回复

72

帖子

0

TA的资源

一粒金砂(初级)

8
 

原来是这样啊!!!

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

怎么才能区别是UART,还是LIN呢????
此帖出自stm32/stm8论坛
 
 
 

回复

76

帖子

0

TA的资源

一粒金砂(初级)

9
 

自已顶

                                 自已顶
此帖出自stm32/stm8论坛
 
 
 

回复

68

帖子

0

TA的资源

一粒金砂(初级)

10
 

顶一个!!!

                                 没有人理我啊!!!
此帖出自stm32/stm8论坛
 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

11
 
为什么我设置UART,反而设置成LIN去了??怎么才能区别是UART,还是LIN呢????
中断向量可能错了。

STM8A库里的中断向量表是有问题的。
此帖出自stm32/stm8论坛
 
 
 

回复

55

帖子

0

TA的资源

一粒金砂(初级)

12
 
                                 寄存器映射有问题,看看汇编是设到什么地址上了
此帖出自stm32/stm8论坛
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表