simplelink_cc13x0_sdk中GPIO的使用

本系列用于对simplelink_cc13x0_sdk的快速使用

1 相关文件

PIN.h : simplelink_cc13x0_sdk_1_60_00_21\source\ti\drivers , 接口函数

GPIOCC26XX.c,GPIOCC26XX.h : E:\TI-RTOS\simplelink_cc13x0_sdk_1_60_00_21\source\ti\drivers\gpio , 具体实现


2 使用示例

static PIN_Handle ledPinHandle;
void led_init()
{
   PIN_State ledPinState;
    PIN_Config ledPinTable[] = {
        Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW  | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        PIN_TERMINATE
    };
    ledPinHandle = PIN_open(&ledPinState, ledPinTable);
    PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, CC1310_LAUNCHXL_GPIO_LED_ON);
}

void led_on()
{
    PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, Board_LED_ON);
}

void led_off()
{
    PIN_setOutputValue(ledPinHandle, Board_PIN_LED0, Board_LED_OFF);
}

void led_reverse()
{
    PIN_setOutputValue(ledPinHandle, Board_PIN_LED0,!PIN_getOutputValue(Board_PIN_LED0));
}

void led_close()
{
    PIN_close(ledPinHandle);
}

3 备注

GPIO引脚定义用这三个文件管理 CC1310_LAUNCHXL.h,CC1310_LAUNCHXL.c,Board。例如上例中的Board_PIN_LED0,首先在Board中

#define Board_PIN_LED0    CC1310_LAUNCHXL_PIN_RLED

然后在CC1310_LAUNCHXL文件中才被实际性指向

#define CC1310_LAUNCHXL_PIN_RLED  IOID_1

写程序前最好先更加自己的硬件对这几个文件进行配置,默认是使用的TI 开发板


还有点值得注意的是,在CC1310_LAUNCHXL.c中很可能是对一些默认使用的GPIO进行初始化的,首先在主函数中查看是否调用了init的函数,然后跳转过去就会发现类似下列代码:

/*
 *  ======== CC1310_LAUNCHXL_initGeneral ========
 */
void CC1310_LAUNCHXL_initGeneral(void)
{
    Power_init();

    if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) {
        /* Error with PIN_init */
        while (1);
    }

}

BoardGpioInitTable结构体就在同文件中可以看到:

/*
 *  =============================== PIN ===============================
 */
#include <ti/drivers/PIN.h>
#include <ti/drivers/pin/PINCC26XX.h>

const PIN_Config BoardGpioInitTable[] = {

//    CC1310_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* LED initially off          */
//    CC1310_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,       /* LED initially off          */
//    CC1310_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,          /* Button is active low       */
//    CC1310_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,          /* Button is active low       */
//    CC1310_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN,  /* External flash chip select */
//    CC1310_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN,                                              /* UART RX via debugger back channel */
//    CC1310_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL,                        /* UART TX via debugger back channel */
    CC1310_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master out - slave in */
    CC1310_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN,                                            /* SPI master in - slave out */
    CC1310_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN,                                             /* SPI clock */

    PIN_TERMINATE
};
他这里都是用的是宏定义,所以最方便的方式就是在.h文件中直接修改IO的宏定义,不使用的全部设置为PIN_UNASSIGNED即可

补充:

注册中断回调

  if (PIN_registerIntCb(buttonPinHandle, &buttonCallbackFxn) != 0) {
    System_abort("Error registering button callback function");
  }

示例中断回调函数

void buttonCallbackFxn(PIN_Handle handle, PIN_Id pinId)
{
   PIN_getInputValue(pinId);//读取电平
   if ( pinId == Board_BUTTON0 )
      PIN_setOutputValue(ledPinHandle, Board_LED0, !PIN_getOutputValue(Board_LED0);
 
}

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值