请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:LAUNCHXL-CC1312R1 主题中讨论的其他器件:CC1312R
您好!
按下 launchpad 上的用户按钮时、我正在尝试在终端上打印字符串。 但代码不起作用。
请帮助了解我在这里遗漏的内容。
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART2.h>
/* Driver configuration */
#include "ti_drivers_config.h"
UART2_Handle uart;
UART2_Params uartParams;
const char b[] = "Positive\r\n";
const char c[] = "Negative\r\n";
size_t bytes_written;
void gpioButtonIsr(uint_least8_t index)
{
GPIO_disableInt(CONFIG_GPIO_BUTTON_0);
GPIO_toggle(CONFIG_GPIO_LED_0);
UART2_write(uart,b,sizeof(b),&bytes_written);
GPIO_enableInt(CONFIG_GPIO_BUTTON_0);
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
const char welcome[] = "Welcome....\r\n";
/* Call driver init functions */
GPIO_init();
UART2_Params_init(&uartParams);
uartParams.readMode = UART2_Mode_CALLBACK;
uartParams.writeMode = UART2_Mode_CALLBACK;
uartParams.baudRate = 115200;
uart = UART2_open(CONFIG_UART2_0,&uartParams);
if(uart==NULL){while(1);}
/* Configure the LED and button pins */
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
GPIO_setConfig(CONFIG_GPIO_BUTTON_0, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
/* Turn on user LED */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
/* Install Button callback */
GPIO_setCallback(CONFIG_GPIO_BUTTON_0, gpioButtonIsr);
GPIO_enableInt(CONFIG_GPIO_BUTTON_0);
UART2_write(uart,welcome,sizeof(welcome),&bytes_written);
return(NULL);
}