打印
[技术问题解答]

跪求KL25Z UART 模块程序,我的事CW10.6,不要IAR的(已解决)

[复制链接]
1414|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
870205766|  楼主 | 2014-5-8 19:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
沙发
FSL_TICS_A| | 2014-5-9 09:42 | 只看该作者
楼主,你好!
你可以按照快速入门手册,自己写UART程序,
同时也可以使用PE的UART组件来做,在组件中有个Help功能,可以帮你理解组件如何配置!
KLQRUG.pdf (2.04 MB)

使用特权

评论回复
板凳
870205766|  楼主 | 2014-5-9 10:13 | 只看该作者
FSL_TICS_A 发表于 2014-5-9 09:42
楼主,你好!
你可以按照快速入门手册,自己写UART程序,
同时也可以使用PE的UART组件来做,在组件中有个He ...

PE的UART组件哪里有呀

使用特权

评论回复
地板
870205766|  楼主 | 2014-5-9 10:14 | 只看该作者
FSL_TICS_A 发表于 2014-5-9 09:42
楼主,你好!
你可以按照快速入门手册,自己写UART程序,
同时也可以使用PE的UART组件来做,在组件中有个He ...

#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "Blue_LED.h"
#include "Green_LED.h"
#include "Red_LED.h"
#include "CsIO1.h"
#include "IO1.h"
#include "PE_LDD.h"


没有发现UART 组件呀,

使用特权

评论回复
5
FSL_TICS_A| | 2014-5-9 10:38 | 只看该作者
870205766 发表于 2014-5-9 10:14
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"

楼主看来你对CW真的熟悉,
建议可以你可以参考一下此入门贴,熟悉一下CW,
还有KLQRUG中的UART章节对如何对UAR配置介绍的很详细啊,完全可以参考的啊!
入门贴:https://bbs.21ic.com/icview-619446-1-1.html

使用特权

评论回复
6
匿名  2014-5-13 16:30
void hw_uart_init()
{
        unsigned short uartclk_khz = 23961;   
        unsigned short baud = 19200;   
        unsigned short sbr,brfa;   
                          
        SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;         /* Enable the clock to the selected UART */        
        SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK;         /* Turn on all port clocks */   
        /* Enable the UART0_TXD function on PTE0 */   
        PORTE_PCR16 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin   
        /* Enable the UART0_RXD function on PTE1 */   
        PORTE_PCR17 = PORT_PCR_MUX(0x3); // UART is alt3 function for this pin        
        sbr = (unsigned short)((uartclk_khz *1000)/(baud * 16));   
        UART2_BDH = (unsigned char)((sbr & 0x1F00) >> 8);   
        UART2_BDL = (unsigned char)(sbr & 0x00FF);   
        /* Determine if a fractional divider is needed to get closer to the baud rate */   
        brfa = (((uartclk_khz*32000)/(baud * 16)) - (sbr * 32));         
        UART2_C4 = (unsigned char)(brfa & 0x001F);               
        UART2_C1 = 0;         /* Configure the UART for 8-bit mode, no parity */          
        UART2_C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK );      /* Enable receiver and transmitter */
       
        UART2_S1|=UART_S1_RDRF_MASK;    /* receiver 中断标志位清零 */
        UART2_C2|=UART_C2_RIE_MASK;    /* Enable receiver 中断 */
        enable_irq(14);                /*开IRQ接收中断*/
}


//=========================================================================
//函数名称:hw_uart_re1
//参数说明:uartNo: 串口号
//          fp:接收成功标志的指针:*p=0,成功接收;*p=1,接收失败
//函数返回:接收返回字节
//功能概要:串行接收1个字节
//=========================================================================
unsigned char uart_getchar (void)
{   
/* Wait until character has been received */   
while (!(UART2_S1 & UART_S1_RDRF_MASK));        
/* Return the 8-bit data from the receiver */   
return UART2_D;
}


void uart_putchar (unsigned char data)
{   
/* Wait until space is available in the FIFO */   
while(!(UART2_S1 & UART_S1_TDRE_MASK));        
/* Send the character */   
UART2_D = data;
}


void uart_ReN (uint8* buff,uint16 len)
{
        int i;
        for(i=0;i<len;i++)
            {
                buff=uart_getchar();
            }
}


void uart_sendN (uint8* buff,uint16 len)
{
    int i;
    for(i=0;i<len;i++)
    {
        uart_putchar(buff);
    }
}


void uart_sendStr (const uint8* str)
{
    while(*str)
    {
        uart_putchar(*str++);
    }
}
void uart_getStrs(uint8* str)
{
        int i;
                for(i=0;uart_getchar()!= '\0';i++)
                    {
                        str=uart_getchar();
                    }      
}

使用特权

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

本版积分规则

26

主题

103

帖子

1

粉丝