wuxiubo 发表于 2022-9-15 22:11

[AT32WB415测评]之简单搞定蓝牙小车功能

本帖最后由 muyichuan2012 于 2022-9-16 16:08 编辑

蓝牙小车在我之前的分享中就有的,所以本次我们就结合雅特力的板子进行一个简单的移植操作吧。void car_stop()

{

gpio_bits_write(GPIOB,GPIO_PINS_8,FALSE);

gpio_bits_write(GPIOB,GPIO_PINS_9,FALSE);


gpio_bits_write(GPIOA,GPIO_PINS_4,FALSE);

gpio_bits_write(GPIOA,GPIO_PINS_5,FALSE);

}

void car_advence()

{

gpio_bits_write(GPIOB,GPIO_PINS_8,TRUE);

gpio_bits_write(GPIOB,GPIO_PINS_9,FALSE);


gpio_bits_write(GPIOA,GPIO_PINS_4,TRUE);

gpio_bits_write(GPIOA,GPIO_PINS_5,FALSE);

}

void car_back()

{

gpio_bits_write(GPIOB,GPIO_PINS_8,FALSE);

gpio_bits_write(GPIOB,GPIO_PINS_9,TRUE);


gpio_bits_write(GPIOA,GPIO_PINS_4,FALSE);

gpio_bits_write(GPIOA,GPIO_PINS_5,TRUE);

}

void car_left()

{

gpio_bits_write(GPIOB,GPIO_PINS_8,FALSE);

gpio_bits_write(GPIOB,GPIO_PINS_9,TRUE);


gpio_bits_write(GPIOA,GPIO_PINS_4,TRUE);

gpio_bits_write(GPIOA,GPIO_PINS_5,FALSE);

}

void car_right()

{

gpio_bits_write(GPIOB,GPIO_PINS_8,TRUE);

gpio_bits_write(GPIOB,GPIO_PINS_9,FALSE);


gpio_bits_write(GPIOA,GPIO_PINS_4,FALSE);

gpio_bits_write(GPIOA,GPIO_PINS_5,TRUE);

}

void car_gpio_init()

{

gpio_init_type gpio_init_struct;



/* enable the led clock */

crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK|CRM_GPIOB_PERIPH_CLOCK, TRUE);



/* set default parameter */

gpio_default_para_init(&gpio_init_struct);



/* configure the led gpio */

gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;

gpio_init_struct.gpio_out_type= GPIO_OUTPUT_PUSH_PULL;

gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;

gpio_init_struct.gpio_pins = GPIO_PINS_4|GPIO_PINS_5;

gpio_init_struct.gpio_pull = GPIO_PULL_NONE;

gpio_init(GPIOA, &gpio_init_struct);

gpio_init_struct.gpio_pins = GPIO_PINS_8|GPIO_PINS_9;

gpio_init(GPIOB, &gpio_init_struct);

car_stop();

}
定义小车使用的IO口。然后我们使用其中的串口透传来做吧,AT 模式,应该是需要自己进行定义的,不然始终就只能解析三个命令。void tp_mode_rx_handler(void)

{

uint16_t tempval = 0;

if(tp_mode_rx_uart.count > 0)

{

    usart_interrupt_enable(USART3, USART_RDBF_INT, FALSE);

    tp_mode_rx_uart.count--;   

    usart_interrupt_enable(USART3, USART_RDBF_INT, TRUE);

    tempval = tp_mode_rx_uart.buf;

    if(tp_mode_rx_uart.buf == 0x0d&& tp_mode_rx_uart.buf == 0x0a)

    {

      tp_mode_rx_uart.recv_end = SET;

    }

switch(tp_mode_rx_uart.buf)

{

case 0x00:

{

car_stop();

break;

}

case 0x01:

{

car_advence();

break;

}

case 0x02:

{

car_back();

break;

}

case 0x03:

{

car_left();

break;

}

case 0x04:

{

car_right();

break;

}

default:

      {

          break;

      }

}

    if(tp_mode_rx_uart.tail > (USART_RECV_LEN - 1))

    {

      tp_mode_rx_uart.tail = 0;

    }      

    while(usart_flag_get(USART2, USART_TDBE_FLAG) !=SET);

    usart_data_transmit(USART2, tempval);

}

}
串口透传在接收中进行函数解析。这里就接收一位,所以直接在头文件中定义下接收长度。剩下就是QT开发了,QT下此设备属于低功耗蓝牙,我们找个例程搞定他即可。其串口透传两个特征,需要QT程序判断,不然连接上也不能发送。最后看下视频吧。【雅特力开发板 WB415蓝牙小车】 https://www.bilibili.com/video/BV1Qd4y137Ac?share_source=copy_web&vd_source=438f4eeebb70305750f92767b803307ahttps://www.bilibili.com/video/BV1Qd4y137Ac?share_source=copy_web&vd_source=438f4eeebb70305750f92767b803307a

muyichuan2012 发表于 2022-9-16 16:16

本帖最后由 muyichuan2012 于 2022-9-16 16:19 编辑

楼主相关资料会分享出来吗? 比如MCU工程文件、手机app安装包

foxsbig 发表于 2022-10-3 14:49

真希望能有详细的资料啊

chenjun89 发表于 2022-10-4 09:48

可以插入视频了?我之前一直操作不行。

Jacquetry 发表于 2022-10-4 21:07

视频得用外链吧

Undshing 发表于 2022-10-5 20:46

我以前也搞过这小车
页: [1]
查看完整版本: [AT32WB415测评]之简单搞定蓝牙小车功能