资源简介
ROS下使用rosserial和STM32(ST库)进行通信,4轮驱动MDK5工程
代码片段和文件信息
#include “hardwareserial.h“
#include “interrupt.h“
USART_TypeDef* SERIAL_USART[SERIALn] = {RIKI_SERIAL1 RIKI_SERIAL2 RIKI_SERIAL3};
GPIO_TypeDef* SERIAL_PORT[SERIALn] = {RIKI_SERIAL1_GPIO_PORT RIKI_SERIAL2_GPIO_PORT RIKI_SERIAL3_GPIO_PORT};
const uint32_t SERIAL_USART_CLK[SERIALn] = {RIKI_SERIAL1_CLK RIKI_SERIAL2_CLK RIKI_SERIAL3_CLK};
const uint32_t SERIAL_PORT_CLK[SERIALn] = {RIKI_SERIAL1_GPIO_CLK RIKI_SERIAL2_GPIO_CLK RIKI_SERIAL3_GPIO_CLK};
const uint16_t SERIAL_TX_PIN[SERIALn] = {RIKI_SERIAL1_TX_PIN RIKI_SERIAL2_TX_PIN RIKI_SERIAL3_TX_PIN};
const uint16_t SERIAL_RX_PIN[SERIALn] = {RIKI_SERIAL1_RX_PIN RIKI_SERIAL2_RX_PIN RIKI_SERIAL2_RX_PIN};
const uint16_t SERIAL_IRQn[SERIALn] = {RIKI_SERIAL1_IRQ RIKI_SERIAL2_IRQ RIKI_SERIAL3_IRQ};
const uint16_t SERILA_NVIC[SERIALn] = {RIKI_SERIAL1_NVIC RIKI_SERIAL2_NVIC RIKI_SERIAL3_NVIC};
HardwareSerial::HardwareSerial(Serial_TypeDef _Serial)
{
Serial = _Serial;
if(this->Serial == SERIAL1)
Serial1 = this;
if(this->Serial == SERIAL2)
Serial2 = this;
if(this->Serial == SERIAL3)
Serial3 = this;
}
void HardwareSerial::begin(uint32_t baud)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
if(this->Serial == SERIAL1) {
RCC_APB2PeriphClockCmd(SERIAL_USART_CLK[this->Serial]|SERIAL_PORT_CLK[this->Serial] ENABLE);
} else {
RCC_APB1PeriphClockCmd(SERIAL_USART_CLK[this->Serial] ENABLE);
RCC_APB2PeriphClockCmd(SERIAL_PORT_CLK[this->Serial] ENABLE);
}
//USART_TX
GPIO_InitStructure.GPIO_Pin = SERIAL_TX_PIN[this->Serial];
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(SERIAL_PORT[this->Serial] &GPIO_InitStructure);
//USART_RX
GPIO_InitStructure.GPIO_Pin = SERIAL_RX_PIN[this->Serial];
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(SERIAL_PORT[this->Serial] &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = baud;
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(SERIAL_USART[this->Serial] &USART_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = SERIAL_IRQn[this->Serial];
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = SERILA_NVIC[this->Serial];
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(SERIAL_USART[this->Serial] USART_IT_RXNE ENABLE);
USART_Cmd(SERIAL_USART[this->Serial] ENABLE);
}
uint32_t HardwareSerial::available(void)
{
return (uint32_t)(SERIAL_BUFFER_SIZE + rx_buffer._iHead - rx_buffer._iTail) %
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-09-19 16:07 rikirobot_stm32-keil\
文件 119 2018-05-28 13:11 rikirobot_stm32-keil\.gitignore
目录 0 2018-09-18 15:37 rikirobot_stm32-keil\Bsp\
文件 7607 2018-09-18 15:37 rikirobot_stm32-keil\Bsp\config.h
文件 4187 2018-08-13 15:50 rikirobot_stm32-keil\Bsp\hardwareserial.cpp
文件 479 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\hardwareserial.h
文件 447 2018-08-10 16:18 rikirobot_stm32-keil\Bsp\interrupt.cpp
文件 446 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\interrupt.h
文件 608 2018-09-10 17:03 rikirobot_stm32-keil\Bsp\millisecondtimer.c
文件 311 2018-09-10 17:03 rikirobot_stm32-keil\Bsp\millisecondtimer.h
文件 1393 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\RingBuffer.cpp
文件 1353 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\RingBuffer.h
文件 5649 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\ring_buffer.h
文件 172 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\round.h
文件 5926 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\Wire.cpp
文件 3320 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\Wire.h
文件 4208 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\Wireba
文件 4673 2018-05-28 13:11 rikirobot_stm32-keil\Bsp\Wireba
目录 0 2018-09-15 22:06 rikirobot_stm32-keil\Driver\
目录 0 2018-08-15 18:49 rikirobot_stm32-keil\Driver\Battery\
文件 2414 2018-08-15 18:49 rikirobot_stm32-keil\Driver\Battery\battery.cpp
文件 359 2018-05-28 13:11 rikirobot_stm32-keil\Driver\Battery\battery.h
目录 0 2018-09-18 15:37 rikirobot_stm32-keil\Driver\Encoder\
文件 10910 2018-09-18 15:37 rikirobot_stm32-keil\Driver\Encoder\encoder.c
文件 299 2018-05-28 15:24 rikirobot_stm32-keil\Driver\Encoder\encoder.h
目录 0 2018-09-15 13:36 rikirobot_stm32-keil\Driver\gy85\
文件 4090 2018-09-15 13:36 rikirobot_stm32-keil\Driver\gy85\gy85.cpp
文件 1962 2018-05-28 13:11 rikirobot_stm32-keil\Driver\gy85\gy85.h
目录 0 2018-09-15 15:47 rikirobot_stm32-keil\Driver\Key\
文件 1873 2018-09-15 15:47 rikirobot_stm32-keil\Driver\Key\key.c
文件 489 2018-09-15 15:46 rikirobot_stm32-keil\Driver\Key\key.h
............此处省略748个文件信息
相关资源
- stm32 按键实现短按,长按,双击,组
- STM32F407温湿度上传物联网平台
- 基于STM32F4系列的4个编码器4倍频的转
- stm32f103c8串口中断不定长接收基于cu
- STM32F407+OV2640+ONENET
- STM32颜色传感器
- stm32AD采集通过fft求信号频率
- rostcm6检测软件
- 基于STM32开发的数据手套控制机械臂
- STM32 SPI双机中断通信
- STM32F4 CAN1 通讯源码
- 基于STM32F4的小波变换移植含小波分解
- 余松-RouterOS无线教程v62e
- 随机过程(Ross中文版
- 飞控stm32程序
- ROST-CM6软件
- NB物联网模块 STM32+BC28
- stm32f107ptp时钟同步
- ENC28J60最全资料,含51AVRLPCSTM32程序源
- GY6500源代码
- STM32F407 双轮小车 定时器编码器模式测
- 基于STM32C8T6的按键温度双模式控制风
- stm32f103+dht11温湿度传感器例程
- 基于STM32F103的USB键盘程序代码
- stm32 f103RCT6用正点原子Mini板可用的R
- STM32f103循迹小车控制程序源码
- STM32实现GPRS与服务器数据传输
- STM32F103基于keil写的简易示波器
- STM32_旋转倒立摆.rar
- STM32_F1系列FreeRTOS工程模板
评论
共有 条评论