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

[复制链接]
1168|6
 楼主| wuxiubo 发表于 2022-9-15 22:11 | 显示全部楼层 |阅读模式
本帖最后由 muyichuan2012 于 2022-9-16 16:08 编辑

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

  2. {

  3. gpio_bits_write(GPIOB,GPIO_PINS_8,FALSE);

  4. gpio_bits_write(GPIOB,GPIO_PINS_9,FALSE);


  5. gpio_bits_write(GPIOA,GPIO_PINS_4,FALSE);

  6. gpio_bits_write(GPIOA,GPIO_PINS_5,FALSE);

  7. }

  8. void car_advence()

  9. {

  10. gpio_bits_write(GPIOB,GPIO_PINS_8,TRUE);

  11. gpio_bits_write(GPIOB,GPIO_PINS_9,FALSE);


  12. gpio_bits_write(GPIOA,GPIO_PINS_4,TRUE);

  13. gpio_bits_write(GPIOA,GPIO_PINS_5,FALSE);

  14. }

  15. void car_back()

  16. {

  17. gpio_bits_write(GPIOB,GPIO_PINS_8,FALSE);

  18. gpio_bits_write(GPIOB,GPIO_PINS_9,TRUE);


  19. gpio_bits_write(GPIOA,GPIO_PINS_4,FALSE);

  20. gpio_bits_write(GPIOA,GPIO_PINS_5,TRUE);

  21. }

  22. void car_left()

  23. {

  24. gpio_bits_write(GPIOB,GPIO_PINS_8,FALSE);

  25. gpio_bits_write(GPIOB,GPIO_PINS_9,TRUE);


  26. gpio_bits_write(GPIOA,GPIO_PINS_4,TRUE);

  27. gpio_bits_write(GPIOA,GPIO_PINS_5,FALSE);

  28. }

  29. void car_right()

  30. {

  31. gpio_bits_write(GPIOB,GPIO_PINS_8,TRUE);

  32. gpio_bits_write(GPIOB,GPIO_PINS_9,FALSE);


  33. gpio_bits_write(GPIOA,GPIO_PINS_4,FALSE);

  34. gpio_bits_write(GPIOA,GPIO_PINS_5,TRUE);

  35. }

  36. void car_gpio_init()

  37. {

  38. gpio_init_type gpio_init_struct;



  39. /* enable the led clock */

  40. crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK|CRM_GPIOB_PERIPH_CLOCK, TRUE);



  41. /* set default parameter */

  42. gpio_default_para_init(&gpio_init_struct);



  43. /* configure the led gpio */

  44. gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;

  45. gpio_init_struct.gpio_out_type  = GPIO_OUTPUT_PUSH_PULL;

  46. gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;

  47. gpio_init_struct.gpio_pins = GPIO_PINS_4|GPIO_PINS_5;

  48. gpio_init_struct.gpio_pull = GPIO_PULL_NONE;

  49. gpio_init(GPIOA, &gpio_init_struct);

  50. gpio_init_struct.gpio_pins = GPIO_PINS_8|GPIO_PINS_9;

  51. gpio_init(GPIOB, &gpio_init_struct);

  52. car_stop();

  53. }

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

  2. {

  3.   uint16_t tempval = 0;

  4.   if(tp_mode_rx_uart.count > 0)

  5.   {

  6.     usart_interrupt_enable(USART3, USART_RDBF_INT, FALSE);

  7.     tp_mode_rx_uart.count--;   

  8.     usart_interrupt_enable(USART3, USART_RDBF_INT, TRUE);

  9.     tempval = tp_mode_rx_uart.buf[tp_mode_rx_uart.tail++];

  10.     if(tp_mode_rx_uart.buf[tp_mode_rx_uart.tail-2] == 0x0d  && tp_mode_rx_uart.buf[tp_mode_rx_uart.tail-1] == 0x0a)

  11.     {

  12.       tp_mode_rx_uart.recv_end = SET;

  13.     }

  14. switch(tp_mode_rx_uart.buf[0])

  15. {

  16. case 0x00:

  17. {

  18. car_stop();

  19. break;

  20. }

  21. case 0x01:

  22. {

  23. car_advence();

  24. break;

  25. }

  26. case 0x02:

  27. {

  28. car_back();

  29. break;

  30. }

  31. case 0x03:

  32. {

  33. car_left();

  34. break;

  35. }

  36. case 0x04:

  37. {

  38. car_right();

  39. break;

  40. }

  41. default:

  42.         {

  43.           break;

  44.         }

  45. }

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

  47.     {

  48.       tp_mode_rx_uart.tail = 0;

  49.     }      

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

  51.     usart_data_transmit(USART2, tempval);

  52.   }

  53. }

串口透传在接收中进行函数解析。这里就接收一位,所以直接在头文件中定义下接收长度。
图片 1.png
图片 2.png
剩下就是QT开发了,QT下此设备属于低功耗蓝牙,我们找个例程搞定他即可。
图片 3.png
其串口透传两个特征,需要QT程序判断,不然连接上也不能发送。
最后看下视频吧。
muyichuan2012 发表于 2022-9-16 16:16 | 显示全部楼层
本帖最后由 muyichuan2012 于 2022-9-16 16:19 编辑

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

评论

有需要可以分享完整的包  发表于 2022-9-16 17:16
foxsbig 发表于 2022-10-3 14:49 | 显示全部楼层
真希望能有详细的资料啊
chenjun89 发表于 2022-10-4 09:48 来自手机 | 显示全部楼层
可以插入视频了?我之前一直操作不行。
Jacquetry 发表于 2022-10-4 21:07 | 显示全部楼层
视频得用外链吧
Undshing 发表于 2022-10-5 20:46 | 显示全部楼层
我以前也搞过这小车
您需要登录后才可以回帖 登录 | 注册

本版积分规则

67

主题

261

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部
0