Configuring BLE with UART

Learn MoreFAQsTutorials

9 posts / 0 new
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(); } }
  • I tried using different interupt modes:
ke_msg_id_t timer_used_SendRec_SM __SECTION_ZERO(“retention_mem_area0"); //@RETENTION MEMORY uart_t * uart = UART2; const int READ_CHAR_COUNT = 5; static char buffer_BLE[READ_CHAR_COUNT + 1]; volatile bool uart_receive_finished = false; volatile uint16_t data_received_cnt = 0; //Function Definitions 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()".

In case of interrupted receives, I use the said timer. However, the program runs only once. In other words, it only prints"Checking the buffer!"and regardless of what I would do, everything would freeze.

  • 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
Offline
Last seen:4 hours 52 min 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

So, my problem was with the app_easy_timer. I had forgotten to call this function again inside the callback. Therefore, it would only run once. If you think you have the same problem, you can check one of the examples of using this function in the SDK.

PM_Dialog
Offline
Last seen:4 hours 52 min ago
Staff
加入:2018-02-08 11:03
Hi There,

Hi There,

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
Thank you very much for your

Thank you very much for your reply. I will try this method.