• 大小: 10.79MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-17
  • 语言: 其他
  • 标签: ROS  STM32  MDK  

资源简介

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\Wirebase.cpp
     文件        4673  2018-05-28 13:11  rikirobot_stm32-keil\Bsp\Wirebase.h
     目录           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个文件信息

评论

共有 条评论