网站怎么做支付宝接口,潍坊做网站软件,工程建设合同模板,开发软件的网站平台目录API (机翻)上机实战引脚配置ADC引脚配置串口引脚配置指示工作状态的LED1引脚配置代码部分ADC初始化和读取函数myADC.cmyADC.h获取数据并通过串口发送main.cmain.h任务管理函数myTask.cmyTask.h串口代码myUart.cmyUart.h实验结果平台#xff1a;Code Composer Studio 10.4.…
目录API (机翻)上机实战引脚配置ADC引脚配置串口引脚配置指示工作状态的LED1引脚配置代码部分ADC初始化和读取函数myADC.cmyADC.h获取数据并通过串口发送main.cmain.h任务管理函数myTask.cmyTask.h串口代码myUart.cmyUart.h实验结果平台Code Composer Studio 10.4.0 MSP432P401R SimpleLink™ 微控制器 LaunchPad™ 开发套件 (MSP-EXP432P401R) API (机翻)
ADC API 官方手册
void ADC_close (ADC_Handle handle)
关闭ADC驱动实例int_fast16_t ADC_control (ADC_Handle handle, uint_fast16_t cmd, void *arg)
在驱动程序实例上执行特定的实现特性int_fast16_t ADC_convert (ADC_Handle handle, uint16_t *value)
执行ADC转换uint32_t ADC_convertToMicroVolts (ADC_Handle handle, uint16_t adcValue)
将原始ADC数据转换为以微伏为单位的数据void ADC_init (void)
初始化ADC驱动程序ADC_Handle ADC_open (uint_least8_t index, ADC_Params *params)
初始化ADC外设void ADC_Params_init (ADC_Params *params)
将ADC_Params结构初始化为其默认值上机实战
引脚配置
ADC引脚配置 串口引脚配置 指示工作状态的LED1引脚配置 代码部分
ADC初始化和读取函数
myADC.c
/** myADC.c** Created on: 2021年8月4日* Author: Royic*/#include ./inc/myADC.hADC_Handle hadc1;void My_ADC_Init(ADC_Handle *adcHandle, uint_least8_t index)
{// One-time init of ADC driverADC_init();// initialize optional ADC parametersADC_Params params;ADC_Params_init(params);params.isProtected true;// Open ADC channels for usage*adcHandle ADC_open(index, params);
}uint32_t Get_Micro_Volts(ADC_Handle *adcHandle)
{uint16_t AdcRaw 0;// Sample the analog output from the ThermocoupleADC_convert(*adcHandle, AdcRaw);// Convert the sample to microvoltsreturn ADC_convertToMicroVolts(*adcHandle, AdcRaw);
}
myADC.h
/** myADC.h** Created on: 2021年8月4日* Author: Royic*/#ifndef INC_MYADC_H_
#define INC_MYADC_H_#include ./inc/main.h// Import ADC Driver definitions
#include ti/drivers/ADC.hvoid My_ADC_Init(ADC_Handle *adcHandle, uint_least8_t index);
uint32_t Get_Micro_Volts(ADC_Handle *adcHandle);extern ADC_Handle hadc1;#endif /* INC_MYADC_H_ */
获取数据并通过串口发送
main.c
/** main_tirtos.c */#include ./inc/main.h/* POSIX Header files */
#include pthread.h/* RTOS header files */
#include ti/sysbios/BIOS.h/* Driver configuration */
#include ti/drivers/Board.h
#include ti/drivers/GPIO.h#include ./inc/myTask.h
#include ./inc/myADC.h
#include ./inc/myUart.h/** main */
int main(void)
{/* Call driver init functions */Board_init();GPIO_init();My_Task_Init(mainThread, 1, 1024);BIOS_start();return (0);
}/** mainThread */
void *mainThread(void *arg0)
{My_Task_Init(LED_Task, 1, 1024);My_Uart_Init(huart1, USB_UART, 115200);My_ADC_Init(hadc1, ADC1);while(1){UART_printf(huart1, %d\r\n, Get_Micro_Volts(hadc1));usleep(1000);}
}
main.h
/** main.h** Created on: 2021年8月2日* Author: Royic*/#ifndef INC_MAIN_H_
#define INC_MAIN_H_/* For usleep() */
#include unistd.h
#include stdint.h
#include stddef.h/* Driver configuration */
#include ti_drivers_config.h#endif /* INC_MAIN_H_ */
任务管理函数
myTask.c
/** myTask.c** Created on: 2021年8月2日* Author: Royic*//* POSIX Header files */
#include pthread.h/* RTOS header files */
#include ti/sysbios/BIOS.h#include ./inc/myTask.h/* Driver Header files */
#include ti/drivers/GPIO.hvoid My_Task_Init(void *(*startroutine)(void *), int priority, size_t stacksize)
{pthread_t thread;pthread_attr_t attrs;struct sched_param priParam;int retc;/* Initialize the attributes structure with default values */pthread_attr_init(attrs);/* Set priority, detach state, and stack size attributes */priParam.sched_priority priority;retc pthread_attr_setschedparam(attrs, priParam);retc | pthread_attr_setdetachstate(attrs, PTHREAD_CREATE_DETACHED);retc | pthread_attr_setstacksize(attrs, stacksize);if (retc ! 0){/* failed to set attributes */while (1){}}retc pthread_create(thread, attrs, startroutine, NULL);if (retc ! 0){/* pthread_create() failed */while (1){}}
}void *LED_Task(void *arg0)
{while(1){GPIO_toggle(LED1);sleep(1);}
}
myTask.h
/** myTask.h** Created on: 2021年8月2日* Author: Royic*/#ifndef INC_MYTASK_H_
#define INC_MYTASK_H_#include ./inc/main.hvoid *mainThread(void *arg0);
void My_Task_Init(void *(*startroutine)(void *), int priority, size_t stacksize);void *LED_Task(void *arg0);#endif /* INC_MYTASK_H_ */
串口代码
myUart.c
/** myUart.c** Created on: 2021年8月3日* Author: Royic*/#include ./inc/myUart.h#include ti/drivers/GPIO.hUART_Handle huart1;char Uart_Rx_Buffer[Uart_Rx_Buffer_Size] {0};void Uart_TxCallback_Func(UART_Handle handle, void *buf, size_t count)
{}void Uart_RxCallback_Func(UART_Handle handle, void *buf, size_t count)
{UART_read(huart1, Uart_Rx_Buffer, 32);
}void My_Uart_Init(UART_Handle *huart, uint_least8_t index, uint32_t BaudRate)
{UART_Params uartParams;// Initialize the UART driver. UART_init() must be called before// calling any other UART APIs.UART_init();// Create a UART with data processing off.UART_Params_init(uartParams);uartParams.readMode UART_MODE_CALLBACK;
// uartParams.writeMode UART_MODE_CALLBACK;uartParams.writeMode UART_MODE_BLOCKING;uartParams.readCallback Uart_RxCallback_Func;uartParams.writeCallback Uart_TxCallback_Func;uartParams.writeDataMode UART_DATA_TEXT;uartParams.readDataMode UART_DATA_TEXT;uartParams.readReturnMode UART_RETURN_NEWLINE;uartParams.readEcho UART_ECHO_OFF;uartParams.baudRate BaudRate;// Open an instance of the UART drivers*huart UART_open(index, uartParams);if (*huart NULL){// UART_open() failedwhile (1);}UART_read(*huart, Uart_Rx_Buffer, 32);
}#include string.h
#include stdarg.h
#include stdio.h
void UART_printf(UART_Handle handle, const char *format,...)
{uint32_t length;va_list args;char TxBuffer[32] {0};va_start(args, format);length vsnprintf((char*)TxBuffer, sizeof(TxBuffer)1, (char*)format, args);va_end(args);UART_write(handle, TxBuffer, length);
}
myUart.h
/** myUart.h** Created on: 2021年8月3日* Author: Royic*/#ifndef INC_MYUART_H_
#define INC_MYUART_H_#include ./inc/main.h// Import the UART driver definitions
#include ti/drivers/UART.h#define Uart_Rx_Buffer_Size 32extern char Uart_Rx_Buffer[Uart_Rx_Buffer_Size];void My_Uart_Init(UART_Handle *huart, uint_least8_t index, uint32_t BaudRate);
void UART_printf(UART_Handle handle, const char *format,...);//Example
//My_Uart_Init(huart1, USB_UART, 115200);
//UART_write(huart1, OK\r\n, 5);extern UART_Handle huart1;#endif /* INC_MYUART_H_ */
实验结果
接上电位器打开上位机转动电位器得到如下波形 数据单位为微伏。