学习STM32Core平台串口2连接维特智能串口Normal协议,然后通过串口1直接连接舵机控制板(TTL),接收进行通信;需要看产品文档的可以直接官网搜索文档。
16路舵机控制板官方产品网址
在查看这个例程前请阅读相关说明书,了解舵机控制板所使用的协议,以及控制板的基本功能、 点击查看16路舵机控制板
16路舵机控制板
1、’可同时支持16路舵机大的输出 2、支持TTL 串口通信 3、支持上位机软件控制动作以及动作组 4、串口初始化为9600
如下图所示为官方提供资料
实物图图下
硬件操作流程 第一种 stm32控制板-------------usart1-------------------->16路舵机控制板 第二种 上位机软件 --------------usb ---------------16路舵机控制班。
上位机软件如下图
我的接线图 下面我用自己的开发板接的如下如 ,(16路舵机控制板) 设计采用的芯片是STM32F103ZET6,采用的16路舵机控制板,自主进行电路设计,通过串口传输,完成对16路舵机控制板串口通信完成动作。
下面直接上示例代码,(可下载官方的代码参考移植,上面有官网地址)-
主函数
void UART1_Put_StringL(unsigned char *Str,unsigned char len)
{
unsigned char i = 0;
for (i=0;i<len;i++) UART1_Put_Char(*(Str + i));
}
void UART_DM_ReportData(unsigned char data[])
{
UART1_Put_StringL(data,10);
}
int main()
{
u8 i=0;
SysTick_Init(72);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
LED_Init();
USART1_Init(9600);
while(1)
{
UART_DM_ReportData(DM0_Speed20_Position_90);
delay_ms(10000);
UART_DM_ReportData(DM0_Speed20_Position_0);
delay_ms(10000);
UART_DM_ReportData(DM_Action0);
delay_ms(2000);
}
}
串口文件参考
#include "usart.h"
#include "system.h"
#include "string.h"
#include <stdio.h>
#include "system.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_rcc.h"
#include "misc.h"
#include "bool.h"
static unsigned char TxBuffer[256];
static unsigned char TxCounter=0;
static unsigned char count=0;
extern void CopeSerial1Data(unsigned char ucData);
int fputc(int ch,FILE *p)
{
USART_SendData(USART1,(u8)ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
return ch;
}
u8 USART1_RX_BUF[USART1_REC_LEN];
u16 USART1_RX_STA=0;
void USART1_Init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = bound;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
USART_ClearFlag(USART1, USART_FLAG_TC);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void UART1_Put_Char(unsigned char DataToSend)
{
TxBuffer[count++] = DataToSend;
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
}
void UART1_Put_String(unsigned char *Str)
{
while(*Str)
{
if(*Str=='\r')UART1_Put_Char(0x0d);
else if(*Str=='\n')UART1_Put_Char(0x0a);
else UART1_Put_Char(*Str);
Str++;
}
}
void CopeSerial1Data(unsigned char ucData)
{
}
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
{
USART_SendData(USART1, TxBuffer[TxCounter++]);
if(TxCounter == count)
{
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
}
USART_ClearITPendingBit(USART1, USART_IT_TXE);
}
else if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
CopeSerial1Data((unsigned char)USART1->DR);
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
}
USART_ClearITPendingBit(USART1,USART_IT_ORE);
}
bool 官方参数直接下载拿过来用
#ifndef _bool_H
#define _bool_H
static unsigned char DM0_Speed1_Position_90[15] = { 0xff, 0x01, 0x00, 0x01, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed2_Position_90[15] = { 0xff, 0x01, 0x00, 0x02, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed3_Position_90[15] = { 0xff, 0x01, 0x00, 0x03, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed4_Position_90[15] = { 0xff, 0x01, 0x00, 0x04, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed5_Position_90[15] = { 0xff, 0x01, 0x00, 0x05, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed6_Position_90[15] = { 0xff, 0x01, 0x00, 0x06, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed7_Position_90[15] = { 0xff, 0x01, 0x00, 0x07, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed8_Position_90[15] = { 0xff, 0x01, 0x00, 0x08, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed9_Position_90[15] = { 0xff, 0x01, 0x00, 0x09, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed10_Position_90[15] = { 0xff, 0x01, 0x00, 0x0a, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed11_Position_90[15] = { 0xff, 0x01, 0x00, 0x0b, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed12_Position_90[15] = { 0xff, 0x01, 0x00, 0x0c, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed13_Position_90[15] = { 0xff, 0x01, 0x00, 0x0d, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed14_Position_90[15] = { 0xff, 0x01, 0x00, 0x0e, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed15_Position_90[15] = { 0xff, 0x01, 0x00, 0x0f, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed16_Position_90[15] = { 0xff, 0x01, 0x00, 0x10, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed17_Position_90[15] = { 0xff, 0x01, 0x00, 0x11, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed18_Position_90[15] = { 0xff, 0x01, 0x00, 0x12, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed19_Position_90[15] = { 0xff, 0x01, 0x00, 0x13, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed20_Position_90[15] = { 0xff, 0x01, 0x00, 0x14, 0x00, 0xff, 0x02, 0x00, 0xdc, 0x05 };
static unsigned char DM0_Speed1_Position_0[15] = { 0xff, 0x01, 0x00, 0x01, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed2_Position_0[15] = { 0xff, 0x01, 0x00, 0x02, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed3_Position_0[15] = { 0xff, 0x01, 0x00, 0x03, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed4_Position_0[15] = { 0xff, 0x01, 0x00, 0x04, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed5_Position_0[15] = { 0xff, 0x01, 0x00, 0x05, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed6_Position_0[15] = { 0xff, 0x01, 0x00, 0x06, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed7_Position_0[15] = { 0xff, 0x01, 0x00, 0x07, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed8_Position_0[15] = { 0xff, 0x01, 0x00, 0x08, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed9_Position_0[15] = { 0xff, 0x01, 0x00, 0x09, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed10_Position_0[15] = { 0xff, 0x01, 0x00, 0x0a, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed11_Position_0[15] = { 0xff, 0x01, 0x00, 0x0b, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed12_Position_0[15] = { 0xff, 0x01, 0x00, 0x0c, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed13_Position_0[15] = { 0xff, 0x01, 0x00, 0x0d, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed14_Position_0[15] = { 0xff, 0x01, 0x00, 0x0e, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed15_Position_0[15] = { 0xff, 0x01, 0x00, 0x0f, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed16_Position_0[15] = { 0xff, 0x01, 0x00, 0x10, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed17_Position_0[15] = { 0xff, 0x01, 0x00, 0x11, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed18_Position_0[15] = { 0xff, 0x01, 0x00, 0x12, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed19_Position_0[15] = { 0xff, 0x01, 0x00, 0x13, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM0_Speed20_Position_0[15] = { 0xff, 0x01, 0x00, 0x14, 0x00, 0xff, 0x02, 0x00, 0xf4, 0x01 };
static unsigned char DM1_Speed1_Position_90[15] = { 0xff, 0x01, 0x01, 0x01, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed2_Position_90[15] = { 0xff, 0x01, 0x01, 0x02, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed3_Position_90[15] = { 0xff, 0x01, 0x01, 0x03, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed4_Position_90[15] = { 0xff, 0x01, 0x01, 0x04, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed5_Position_90[15] = { 0xff, 0x01, 0x01, 0x05, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed6_Position_90[15] = { 0xff, 0x01, 0x01, 0x06, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed7_Position_90[15] = { 0xff, 0x01, 0x01, 0x07, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed8_Position_90[15] = { 0xff, 0x01, 0x01, 0x08, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed9_Position_90[15] = { 0xff, 0x01, 0x01, 0x09, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed10_Position_90[15] = { 0xff, 0x01, 0x01, 0x0a, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed11_Position_90[15] = { 0xff, 0x01, 0x01, 0x0b, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed12_Position_90[15] = { 0xff, 0x01, 0x01, 0x0c, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed13_Position_90[15] = { 0xff, 0x01, 0x01, 0x0d, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed14_Position_90[15] = { 0xff, 0x01, 0x01, 0x0e, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed15_Position_90[15] = { 0xff, 0x01, 0x01, 0x0f, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed16_Position_90[15] = { 0xff, 0x01, 0x01, 0x10, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed17_Position_90[15] = { 0xff, 0x01, 0x01, 0x11, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed18_Position_90[15] = { 0xff, 0x01, 0x01, 0x12, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed19_Position_90[15] = { 0xff, 0x01, 0x01, 0x13, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed20_Position_90[15] = { 0xff, 0x01, 0x01, 0x14, 0x00, 0xff, 0x02, 0x01, 0xdc, 0x05 };
static unsigned char DM1_Speed1_Position_0[15] = { 0xff, 0x01, 0x01, 0x01, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed2_Position_0[15] = { 0xff, 0x01, 0x01, 0x02, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed3_Position_0[15] = { 0xff, 0x01, 0x01, 0x03, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed4_Position_0[15] = { 0xff, 0x01, 0x01, 0x04, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed5_Position_0[15] = { 0xff, 0x01, 0x01, 0x05, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed6_Position_0[15] = { 0xff, 0x01, 0x01, 0x06, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed7_Position_0[15] = { 0xff, 0x01, 0x01, 0x07, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed8_Position_0[15] = { 0xff, 0x01, 0x01, 0x08, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed9_Position_0[15] = { 0xff, 0x01, 0x01, 0x09, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed10_Position_0[15] = { 0xff, 0x01, 0x01, 0x0a, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed11_Position_0[15] = { 0xff, 0x01, 0x01, 0x0b, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed12_Position_0[15] = { 0xff, 0x01, 0x01, 0x0c, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed13_Position_0[15] = { 0xff, 0x01, 0x01, 0x0d, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed14_Position_0[15] = { 0xff, 0x01, 0x01, 0x0e, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed15_Position_0[15] = { 0xff, 0x01, 0x01, 0x0f, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed16_Position_0[15] = { 0xff, 0x01, 0x01, 0x10, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed17_Position_0[15] = { 0xff, 0x01, 0x01, 0x11, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed18_Position_0[15] = { 0xff, 0x01, 0x01, 0x12, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed19_Position_0[15] = { 0xff, 0x01, 0x01, 0x13, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM1_Speed20_Position_0[15] = { 0xff, 0x01, 0x01, 0x14, 0x00, 0xff, 0x02, 0x01, 0xf4, 0x01 };
static unsigned char DM2_Speed1_Position_90[15] = { 0xff, 0x01, 0x02, 0x01, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed2_Position_90[15] = { 0xff, 0x01, 0x02, 0x02, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed3_Position_90[15] = { 0xff, 0x01, 0x02, 0x03, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed4_Position_90[15] = { 0xff, 0x01, 0x02, 0x04, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed5_Position_90[15] = { 0xff, 0x01, 0x02, 0x05, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed6_Position_90[15] = { 0xff, 0x01, 0x02, 0x06, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed7_Position_90[15] = { 0xff, 0x01, 0x02, 0x07, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed8_Position_90[15] = { 0xff, 0x01, 0x02, 0x08, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed9_Position_90[15] = { 0xff, 0x01, 0x02, 0x09, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed10_Position_90[15] = { 0xff, 0x01, 0x02, 0x0a, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed11_Position_90[15] = { 0xff, 0x01, 0x02, 0x0b, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed12_Position_90[15] = { 0xff, 0x01, 0x02, 0x0c, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed13_Position_90[15] = { 0xff, 0x01, 0x02, 0x0d, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed14_Position_90[15] = { 0xff, 0x01, 0x02, 0x0e, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed15_Position_90[15] = { 0xff, 0x01, 0x02, 0x0f, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed16_Position_90[15] = { 0xff, 0x01, 0x02, 0x10, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed17_Position_90[15] = { 0xff, 0x01, 0x02, 0x11, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed18_Position_90[15] = { 0xff, 0x01, 0x02, 0x12, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed19_Position_90[15] = { 0xff, 0x01, 0x02, 0x13, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed20_Position_90[15] = { 0xff, 0x01, 0x02, 0x14, 0x00, 0xff, 0x02, 0x02, 0xdc, 0x05 };
static unsigned char DM2_Speed1_Position_0[15] = { 0xff, 0x01, 0x02, 0x01, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed2_Position_0[15] = { 0xff, 0x01, 0x02, 0x02, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed3_Position_0[15] = { 0xff, 0x01, 0x02, 0x03, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed4_Position_0[15] = { 0xff, 0x01, 0x02, 0x04, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed5_Position_0[15] = { 0xff, 0x01, 0x02, 0x05, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed6_Position_0[15] = { 0xff, 0x01, 0x02, 0x06, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed7_Position_0[15] = { 0xff, 0x01, 0x02, 0x07, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed8_Position_0[15] = { 0xff, 0x01, 0x02, 0x08, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed9_Position_0[15] = { 0xff, 0x01, 0x02, 0x09, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed10_Position_0[15] = { 0xff, 0x01, 0x02, 0x0a, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed11_Position_0[15] = { 0xff, 0x01, 0x02, 0x0b, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed12_Position_0[15] = { 0xff, 0x01, 0x02, 0x0c, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed13_Position_0[15] = { 0xff, 0x01, 0x02, 0x0d, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed14_Position_0[15] = { 0xff, 0x01, 0x02, 0x0e, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed15_Position_0[15] = { 0xff, 0x01, 0x02, 0x0f, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed16_Position_0[15] = { 0xff, 0x01, 0x02, 0x10, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed17_Position_0[15] = { 0xff, 0x01, 0x02, 0x11, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed18_Position_0[15] = { 0xff, 0x01, 0x02, 0x12, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed19_Position_0[15] = { 0xff, 0x01, 0x02, 0x13, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM2_Speed20_Position_0[15] = { 0xff, 0x01, 0x02, 0x14, 0x00, 0xff, 0x02, 0x02, 0xf4, 0x01 };
static unsigned char DM3_Speed10_Position_90[15] = { 0xff, 0x01, 0x03, 0x0a, 0x00, 0xff, 0x02, 0x03, 0xdc, 0x05 };
static unsigned char DM3_Speed20_Position_90[15] = { 0xff, 0x01, 0x03, 0x14, 0x00, 0xff, 0x02, 0x03, 0xdc, 0x05 };
static unsigned char DM3_Speed10_Position_0[15] = { 0xff, 0x01, 0x03, 0x0a, 0x00, 0xff, 0x02, 0x03, 0xf4, 0x01 };
static unsigned char DM3_Speed20_Position_0[15] = { 0xff, 0x01, 0x03, 0x14, 0x00, 0xff, 0x02, 0x03, 0xf4, 0x01 };
static unsigned char DM4_Speed10_Position_90[15] = { 0xff, 0x01, 0x04, 0x0a, 0x00, 0xff, 0x02, 0x04, 0xdc, 0x05 };
static unsigned char DM4_Speed20_Position_90[15] = { 0xff, 0x01, 0x04, 0x14, 0x00, 0xff, 0x02, 0x04, 0xdc, 0x05 };
static unsigned char DM4_Speed10_Position_0[15] = { 0xff, 0x01, 0x04, 0x0a, 0x00, 0xff, 0x02, 0x04, 0xf4, 0x01 };
static unsigned char DM4_Speed20_Position_0[15] = { 0xff, 0x01, 0x04, 0x14, 0x00, 0xff, 0x02, 0x04, 0xf4, 0x01 };
static unsigned char DM5_Speed10_Position_90[15] = { 0xff, 0x01, 0x05, 0x0a, 0x00, 0xff, 0x02, 0x05, 0xdc, 0x05 };
static unsigned char DM5_Speed20_Position_90[15] = { 0xff, 0x01, 0x05, 0x14, 0x00, 0xff, 0x02, 0x05, 0xdc, 0x05 };
static unsigned char DM5_Speed10_Position_0[15] = { 0xff, 0x01, 0x05, 0x0a, 0x00, 0xff, 0x02, 0x05, 0xf4, 0x01 };
static unsigned char DM5_Speed20_Position_0[15] = { 0xff, 0x01, 0x05, 0x14, 0x00, 0xff, 0x02, 0x05, 0xf4, 0x01 };
static unsigned char DM6_Speed10_Position_90[15] = { 0xff, 0x01, 0x06, 0x0a, 0x00, 0xff, 0x02, 0x06, 0xdc, 0x05 };
static unsigned char DM6_Speed20_Position_90[15] = { 0xff, 0x01, 0x06, 0x14, 0x00, 0xff, 0x02, 0x06, 0xdc, 0x05 };
static unsigned char DM6_Speed10_Position_0[15] = { 0xff, 0x01, 0x06, 0x0a, 0x00, 0xff, 0x02, 0x06, 0xf4, 0x01 };
static unsigned char DM6_Speed20_Position_0[15] = { 0xff, 0x01, 0x06, 0x14, 0x00, 0xff, 0x02, 0x06, 0xf4, 0x01 };
static unsigned char DM7_Speed10_Position_90[15] = { 0xff, 0x01, 0x07, 0x0a, 0x00, 0xff, 0x02, 0x07, 0xdc, 0x05 };
static unsigned char DM7_Speed20_Position_90[15] = { 0xff, 0x01, 0x07, 0x14, 0x00, 0xff, 0x02, 0x07, 0xdc, 0x05 };
static unsigned char DM7_Speed10_Position_0[15] = { 0xff, 0x01, 0x07, 0x0a, 0x00, 0xff, 0x02, 0x07, 0xf4, 0x01 };
static unsigned char DM7_Speed20_Position_0[15] = { 0xff, 0x01, 0x07, 0x14, 0x00, 0xff, 0x02, 0x07, 0xf4, 0x01 };
static unsigned char DM8_Speed10_Position_90[15] = { 0xff, 0x01, 0x08, 0x0a, 0x00, 0xff, 0x02, 0x08, 0xdc, 0x05 };
static unsigned char DM8_Speed20_Position_90[15] = { 0xff, 0x01, 0x08, 0x14, 0x00, 0xff, 0x02, 0x08, 0xdc, 0x05 };
static unsigned char DM8_Speed10_Position_0[15] = { 0xff, 0x01, 0x08, 0x0a, 0x00, 0xff, 0x02, 0x08, 0xf4, 0x01 };
static unsigned char DM8_Speed20_Position_0[15] = { 0xff, 0x01, 0x08, 0x14, 0x00, 0xff, 0x02, 0x08, 0xf4, 0x01 };
static unsigned char DM9_Speed10_Position_90[15] = { 0xff, 0x01, 0x09, 0x0a, 0x00, 0xff, 0x02, 0x09, 0xdc, 0x05 };
static unsigned char DM9_Speed20_Position_90[15] = { 0xff, 0x01, 0x09, 0x14, 0x00, 0xff, 0x02, 0x09, 0xdc, 0x05 };
static unsigned char DM9_Speed10_Position_0[15] = { 0xff, 0x01, 0x09, 0x0a, 0x00, 0xff, 0x02, 0x09, 0xf4, 0x01 };
static unsigned char DM9_Speed20_Position_0[15] = { 0xff, 0x01, 0x09, 0x14, 0x00, 0xff, 0x02, 0x09, 0xf4, 0x01 };
static unsigned char DM10_Speed10_Position_90[15] = { 0xff, 0x01, 0x0a, 0x0a, 0x00, 0xff, 0x02, 0x0a, 0xdc, 0x05 };
static unsigned char DM10_Speed20_Position_90[15] = { 0xff, 0x01, 0x0a, 0x14, 0x00, 0xff, 0x02, 0x0a, 0xdc, 0x05 };
static unsigned char DM10_Speed10_Position_0[15] = { 0xff, 0x01, 0x0a, 0x0a, 0x00, 0xff, 0x02, 0x0a, 0xf4, 0x01 };
static unsigned char DM10_Speed20_Position_0[15] = { 0xff, 0x01, 0x0a, 0x14, 0x00, 0xff, 0x02, 0x0a, 0xf4, 0x01 };
static unsigned char DM11_Speed10_Position_90[15] = { 0xff, 0x01, 0x0b, 0x0a, 0x00, 0xff, 0x02, 0x0b, 0xdc, 0x05 };
static unsigned char DM11_Speed20_Position_90[15] = { 0xff, 0x01, 0x0b, 0x14, 0x00, 0xff, 0x02, 0x0b, 0xdc, 0x05 };
static unsigned char DM11_Speed10_Position_0[15] = { 0xff, 0x01, 0x0b, 0x0a, 0x00, 0xff, 0x02, 0x0b, 0xf4, 0x01 };
static unsigned char DM11_Speed20_Position_0[15] = { 0xff, 0x01, 0x0b, 0x14, 0x00, 0xff, 0x02, 0x0b, 0xf4, 0x01 };
static unsigned char DM12_Speed10_Position_90[15] = { 0xff, 0x01, 0x0c, 0x0a, 0x00, 0xff, 0x02, 0x0c, 0xdc, 0x05 };
static unsigned char DM12_Speed20_Position_90[15] = { 0xff, 0x01, 0x0c, 0x14, 0x00, 0xff, 0x02, 0x0c, 0xdc, 0x05 };
static unsigned char DM12_Speed10_Position_0[15] = { 0xff, 0x01, 0x0c, 0x0a, 0x00, 0xff, 0x02, 0x0c, 0xf4, 0x01 };
static unsigned char DM12_Speed20_Position_0[15] = { 0xff, 0x01, 0x0c, 0x14, 0x00, 0xff, 0x02, 0x0c, 0xf4, 0x01 };
static unsigned char DM13_Speed10_Position_90[15] = { 0xff, 0x01, 0x0d, 0x0a, 0x00, 0xff, 0x02, 0x0d, 0xdc, 0x05 };
static unsigned char DM13_Speed20_Position_90[15] = { 0xff, 0x01, 0x0d, 0x14, 0x00, 0xff, 0x02, 0x0d, 0xdc, 0x05 };
static unsigned char DM13_Speed10_Position_0[15] = { 0xff, 0x01, 0x0d, 0x0a, 0x00, 0xff, 0x02, 0x0d, 0xf4, 0x01 };
static unsigned char DM13_Speed20_Position_0[15] = { 0xff, 0x01, 0x0d, 0x14, 0x00, 0xff, 0x02, 0x0d, 0xf4, 0x01 };
static unsigned char DM14_Speed10_Position_90[15] = { 0xff, 0x01, 0x0e, 0x0a, 0x00, 0xff, 0x02, 0x0e, 0xdc, 0x05 };
static unsigned char DM14_Speed20_Position_90[15] = { 0xff, 0x01, 0x0e, 0x14, 0x00, 0xff, 0x02, 0x0e, 0xdc, 0x05 };
static unsigned char DM14_Speed10_Position_0[15] = { 0xff, 0x01, 0x0e, 0x0a, 0x00, 0xff, 0x02, 0x0e, 0xf4, 0x01 };
static unsigned char DM14_Speed20_Position_0[15] = { 0xff, 0x01, 0x0e, 0x14, 0x00, 0xff, 0x02, 0x0e, 0xf4, 0x01 };
static unsigned char DM15_Speed10_Position_90[15] = { 0xff, 0x01, 0x0f, 0x0a, 0x00, 0xff, 0x02, 0x0f, 0xdc, 0x05 };
static unsigned char DM15_Speed20_Position_90[15] = { 0xff, 0x01, 0x0f, 0x14, 0x00, 0xff, 0x02, 0x0f, 0xdc, 0x05 };
static unsigned char DM15_Speed10_Position_0[15] = { 0xff, 0x01, 0x0f, 0x0a, 0x00, 0xff, 0x02, 0x0f, 0xf4, 0x01 };
static unsigned char DM15_Speed20_Position_0[15] = { 0xff, 0x01, 0x0f, 0x14, 0x00, 0xff, 0x02, 0x0f, 0xf4, 0x01 };
static unsigned char DM_Action0[5] = { 0xff, 0x09, 0x00, 0x00, 0x00 };
static unsigned char DM_Action1[5] = { 0xff, 0x09, 0x00, 0x01, 0x00 };
static unsigned char DM_Action2[5] = { 0xff, 0x09, 0x00, 0x02, 0x00 };
static unsigned char DM_Action3[5] = { 0xff, 0x09, 0x00, 0x03, 0x00 };
static unsigned char DM_Action4[5] = { 0xff, 0x09, 0x00, 0x04, 0x00 };
static unsigned char DM_Action5[5] = { 0xff, 0x09, 0x00, 0x05, 0x00 };
static unsigned char DM_Action6[5] = { 0xff, 0x09, 0x00, 0x06, 0x00 };
static unsigned char DM_Action7[5] = { 0xff, 0x09, 0x00, 0x07, 0x00 };
static unsigned char DM_Action8[5] = { 0xff, 0x09, 0x00, 0x08, 0x00 };
static unsigned char DM_Action9[5] = { 0xff, 0x09, 0x00, 0x09, 0x00 };
static unsigned char DM_Action10[5] = { 0xff, 0x09, 0x00, 0x0a, 0x00 };
static unsigned char DM_Action11[5] = { 0xff, 0x09, 0x00, 0x0b, 0x00 };
static unsigned char DM_Action12[5] = { 0xff, 0x09, 0x00, 0x0c, 0x00 };
static unsigned char DM_Action13[5] = { 0xff, 0x09, 0x00, 0x0d, 0x00 };
static unsigned char DM_Action14[5] = { 0xff, 0x09, 0x00, 0x0e, 0x00 };
static unsigned char DM_Action15[5] = { 0xff, 0x09, 0x00, 0x0f, 0x00 };
#endif
总结:
单片机连接舵机控制板进行舵机角度控制,电池电压7.2V 舵机mg996/mg90s 舵机控制板波特率9600 一般的stm32 机 本身就有1到4个PWM 控制输出根据个人情况去定义程序和选择产品 串口通信的常规用法。后期会使用不同的产品更新
上一期学习 STM32之九轴姿态传感器(BWT901CL)串口通信读取数据
|