This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

求一个msp430f5438A的irda demo code

如题求一个红外传输例程,找好久没找到,TI的官方例程里也没找到

  • 目前没有直接的例程,但是给出了相关的文档,您可以参考一下

    https://www.ti.com/lit/an/slaa202b/slaa202b.pdf

    另外有客户分享了之前的程序,您也可以参考一下

    usci_a_uart_IrDA.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    /* --COPYRIGHT--,BSD
    * Copyright (c) 2017, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    * --/COPYRIGHT--*/
    #include "driverlib.h"
    //******************************************************************************
    //! This example shows how to configure the UART module to echo a received
    //! character. To echo a received character, RX ISR is used.
    //!
    //! MSP430F6638
    //! -----------------
    //! /|\| |
    //! | | |
    //! --|RST |
    //! | |
    //! | P2.4/UCA0TXD|------------>
    //! | | 9600
    //! | P2.5/UCA0RXD|<------------
    //!
    //!
    //! This example uses the following peripherals and I/O signals. You must
    //! review these and change as needed for your own board:
    //! - UART peripheral
    //! - GPIO Port peripheral (for UART pins)
    //! - UCA0TXD
    //! - UCA0RXD
    //!
    //! This example uses the following interrupt handlers. To use this example
    //! in your own application you must add these interrupt handlers to your
    //! vector table.
    //! - USCI_A0_VECTOR.
    //******************************************************************************
    #define BAUD_RATE 9600
    #define RECEIVE_DATA_COUNT 0x02
    #define USCI_A_UART_MULTIPROCESSOR_MODE_ADDRESS 0xAA
    #define UCS_XT2_TIMEOUT 50000 //Desired Timeout for XT2 initialization
    #define UCS_XT1_CRYSTAL_FREQUENCY 32768 //XT1 Crystal Frequency being used
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • 很高兴能帮到您!
  • 附上5438A的 IrDa驱动代码 红外模块选用 TFDU4101

    //红外传输功能
    static void IrDAInit (void)
    {
    //引脚复用UART
    P3SEL|=(BIT4+BIT5);
    //P3DS |=(BIT4+BIT5);

    //停止UART,并选择SMCLK作为UART时钟源
    UCA0CTL1 = UCSSEL__SMCLK+UCSWRST;
    //启用红外功能
    UCA0IRCTL = UCIREN;
    //UCA0MCTL=UCOS16;

    //配置速率
    UCA0BR0 = 0X15; // 16000000/57600bps=277.777 取整为277=0x0115
    UCA0BR1 = 0x01;
    //重启UART
    UCA0CTL1 &= ~UCSWRST; // 失能软件复位标志,初始化完成
    UCA0IE |= UCRXIE; // 启用接收中断
    }

    //IrDaSend("hello world!\n",sizeof("hello world!\n"));
    //发送
    static void IrDaSend(u8* string,i32 len)
    {
    i32 idx;

    for(idx=0;idx<len;idx++)
    {
    while (!(UCA0IFG & UCTXIFG));
    UCA0TXBUF = string[idx];
    }
    }

    //接收
    //UART中断
    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    {
    u8 ch;
    switch(__even_in_range(UCA0IV,4))
    {
    case 0:// 无中断 Vector 0 - no interrupt
    break;
    case 2:// 接收中断 Vector 2 - RXIFG
    ch = UCA0RXBUF; //发送单字节数据 TX -> RXed character
    while (!(UCA0IFG & UCTXIFG));// 等待发送缓冲准备 USCI_A0 TX buffer ready?
    UCA0TXBUF=ch;
    break;
    case 4:// 发送中断 Vector 4 - TXIFG
    break;
    default: break;
    }
    }
  • 谢谢您的分享!