ec800m.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "ec800m.h"
  2. #include "usart.h"
  3. #include "string.h"
  4. #include "delay.h"
  5. void EC800MPwoerOn(void)
  6. {
  7. rcu_periph_clock_enable(RCU_GPIOD);
  8. gpio_init(GPIOD, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
  9. gpio_bit_set(GPIOD,GPIO_PIN_2);
  10. Delay_Ms(5000);
  11. gd_pull_EC800M_pwr_up();
  12. gd_pull_EC800M_rst_down();
  13. Delay_Ms(50);
  14. gd_pull_EC800M_pwr_down();
  15. Delay_Ms(320);
  16. gd_pull_EC800M_rst_up();
  17. Delay_Ms(800);
  18. gd_pull_EC800M_pwr_up();
  19. }
  20. void EC800MSendCmd(char *buf, uint16_t len)
  21. {
  22. uint16_t i;
  23. uint16_t data;
  24. for (i = 0; i < len; i++)
  25. {
  26. data = buf[i];
  27. usart_data_transmit(COM_EC800, data);
  28. while (RESET == usart_flag_get(COM_EC800, USART_FLAG_TBE))
  29. ;
  30. }
  31. }
  32. void EC800MWaitReady()
  33. {
  34. WaitResponse(RSP_READY, 5000);
  35. }
  36. /*
  37. * 函数名:bool WaitResponse(char *expectStr, int timeout)
  38. * 输入参数:expectStr 需要匹配的关键�? timeout超时时间
  39. * 输出参数:true flase
  40. * 返回值:�?
  41. * 函数作用:从UART0_RX_BUF缓冲区中匹配有无对应关键字有关键字则返回true无返回false
  42. */
  43. bool WaitResponse(char *expectStr, int timeout)
  44. {
  45. bool timeoutFlag = false;
  46. if (timeout >= 0)
  47. {
  48. timeoutFlag = true;
  49. }
  50. // gd_485_send((char *)&UART0_RX_BUF, strlen(UART0_RX_BUF)); 不清楚�?��?�调�?485意义
  51. while (1)
  52. {
  53. Delay_Ms(50);
  54. if (UART0_RX_STAT > 0)
  55. {
  56. UART0_RX_STAT = 0;
  57. char *p = strstr((char *)&UART0_RX_BUF, expectStr);
  58. if (p)
  59. {
  60. Clear_DMA_Buffer();
  61. return true;
  62. }
  63. }
  64. timeout -= 50;
  65. if (timeoutFlag == true && timeout <= 0)
  66. {
  67. Clear_DMA_Buffer();
  68. return false;
  69. }
  70. };
  71. }