Configuring BLE with UART

Learn MoreFAQsTutorials

9个帖子/ 0新
Last post
hamiddhosseini
Offline
Last seen:3 months 3 days ago
加入:2020-05-12 12:04
Configuring BLE with UART

Hello there,

I'm trying to use UART in parallel with BLE. For the purpose of my project, Codeless and DSPS were not applicable and making adequate modifications was impossible. Therefore, I decided to use the UART functionalities demonstrated in example project in conjuction with ble_app_peripheral example.

That being said, After importing some of the libraries which were required and enabling dma mode in ble example; I followed this proccess:

  • Upon subscription to adc value 1, I want to start reading the data every 5 seconds.
空白user_svc1_adc_val_1_cfg_ind_handler (ke_msg_id_t const msgid, struct custs1_val_write_ind const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { // Generate indication when the central subscribes to it if (param->value[0]){ printf_string(UART2,"The user has subscribed to ADC characteristic!\n\r"); SendRecSM_op(); } }
  • 我尝试使用不同的中断模式:
ke_msg_id_t timer_used_sendrec_sm __section_zero(“保留_mem_area0”);// @保留内存UART_T * UART = UART2;const int read_char_count = 5;静态char buffer_ble [read_char_count + 1];volatile bool uart_receive_finished = false;volatile uint16_t data_received_cnt = 0;//函数定义void sendrecsm_op(){// blocking_receive_uart();intr_receive_uart();// dma_receive_uart();app_easy_timer(500,UART_CHK_BUFFER_CB); } static void uart_receive_cb(uint16_t length){ data_received_cnt = length; uart_receive_finished = true; } void dma_receive_uart(){ uart_receive_finished = false; data_received_cnt = 0; uart_register_rx_cb(uart, uart_receive_cb); //Time to ask for data! uart_receive(uart, (uint8_t *)buffer_BLE, READ_CHAR_COUNT, UART_OP_DMA); } void uart_chk_buffer_cb() { arch_printf("\n\rChecking the buffer!\n\r"); if (uart_receive_finished){ buffer_BLE[READ_CHAR_COUNT] = 0; // make it a null terminated string printf_string(uart,buffer_BLE); } } void intr_receive_uart(){ uart_receive_finished = false; data_received_cnt = 0; uart_register_rx_cb(uart, uart_receive_cb); //Time to ask for data! arch_printf("UART is in Interrupt mode!\n\r"); arch_printf("Please input the data!"); uart_receive(uart, (uint8_t *)buffer_BLE, READ_CHAR_COUNT, UART_OP_INTR); } void blocking_receive_uart(){ printf_string(uart,"UART is in Blocking mode!\n\r"); printf_string(uart,"Please input the data!"); uart_receive(uart, (uint8_t *)buffer_BLE, READ_CHAR_COUNT, UART_OP_BLOCKING); buffer_BLE[READ_CHAR_COUNT] = 0; // make it a null terminated string printf_string(uart,buffer_BLE); }

In case of blocking recieve, I'm not using the timer. However, If I don't input the data right away, the program crashes due to"while (!uart_data_ready_getf(uart_id));"command in"uart_read_byte()".

如果中断接收,我使用所述计时器。但是,该程序仅运行一次。换句话说,它只打印"Checking the buffer!"无论我会做什么,一切都会冻结。

  • If I stick to the original code and use"while(!receive_uart_finished);"the programm will crash due to the same line of code.

I wanted to know, what can I do to solve these problems? Is there a something that I haven't configured for the UART? Is there a better way to do this? (except for using codeless or dsps, because they seem extremely hard to modify)

Device:
PM_Dialog
Online
Last seen:33 sec ago
Staff
加入:2018-02-08 11:03
Hi hamiddhosseini,

Hi hamiddhosseini,

Could you please clarify what you are trying to accomplish? If I understood correct, you just need to print messages over UART? Is my understanding correct? Did you try to print your date using arch_prntf() API?

Which BLE example are you using? Please note if you are using any of the available sleep mode, all the peripherals domains are shut done (including UART). This means that you cannot have any UART activity in sleep mode.

Thanks, PM_Dialog

孙梦君
Offline
Last seen:1 week 3 days ago
加入:2020-03-03 02:40
I have the same problem and

I have the same problem and have defined arch_ SLEEP_ OFF.

in DA14585,SDK6.0.12,ble_app_peripheral.

hamiddhosseini
Offline
Last seen:3 months 3 days ago
加入:2020-05-12 12:04
Hello there,

Hello there,

Thanks for your response, I'm basing my work on BLE_APP_PERIPHERAL example and I was trying to add send and receive data over UART in this example as well.

Now, I have managed to fix the issue. Now I understand that using the blocking mode is not possible in this example. However, I had made a small mistake in writing the callbacks for the interrupt and dma mode.

孙梦君
Offline
Last seen:1 week 3 days ago
加入:2020-03-03 02:40
How did you solve this

How did you solve this problem?

hamiddhosseini
Offline
Last seen:3 months 3 days ago
加入:2020-05-12 12:04
So, my problem was with the

所以,我的问题是App_easy_timer。我忘记在回调中再次调用此函数。因此,它只运行一次。如果您认为您有同样的问题,可以检查在SDK中使用此功能的示例之一。

PM_Dialog
Online
Last seen:33 sec ago
Staff
加入:2018-02-08 11:03
你好呀,

你好呀,

I would recommend using the latest SDK version which is SDK6.0.14. Could you please clarify what your are trying to accomplish, so that I can understand how I can help you?

Thanks, PM_Dialog

hamiddhosseini
Offline
Last seen:3 months 3 days ago
加入:2020-05-12 12:04
Thanks, my issue is solved

Thanks, my issue is solved now. I don't know which part of the question is vague for you, if sth needs to be clarified please let me know.

孙梦君
Offline
Last seen:1 week 3 days ago
加入:2020-03-03 02:40
非常感谢你的

非常感谢您的回复。我会尝试这种方法。