want to add command mode and data mode in DSPS sdk.

Hi Team,

Iam using DSPS sdk: 6.150.6.77, DA14531MOD.

As per my requirement i have to use DSPS sdk for high data flow.

So, further i want to add other feature like,

1. when BT module not connected to host Application it should be set to command mode.

2. when BT module connected to host Application it should be in data mode.

please let me know at which piece of code App connection and disconnection flags are placed.

Regards,

Laxmi Narayana.

Parents Reply Children
  • Hi Laxmi,

    OV has created one demo for responding BD address, you can take this as a reference: 

    I worked on the SPS SDK v6.150.6.77 with Security enabled.
    At the top of the user_sps_device_dma.c file I added the following functions:

    #include "user_periph_setup.h"
    #include "uart.h"
    uint8_t addr2[BD_ADDR_LEN] = {0}; 
    static void enable_uart1()
    {
            //Configure UART pins for 2-Wire UART
        GPIO_ConfigurePin(gpio_uart1_tx.port, gpio_uart1_tx.pin, OUTPUT, PID_UART1_TX, false);
        GPIO_ConfigurePin(gpio_uart1_rx.port, gpio_uart1_rx.pin, INPUT_PULLUP, PID_UART1_RX, false);
        GPIO_ConfigurePin(gpio_uart1_rts.port, gpio_uart1_rts.pin, INPUT_PULLUP, PID_GPIO, false);
        GPIO_ConfigurePin(gpio_uart1_cts.port, gpio_uart1_cts.pin, INPUT_PULLUP, PID_GPIO, false);
            //Uart Configuration
        uart_cfg_t uart_cfg = {
            .baud_rate = UART_BAUDRATE_921600,
            .data_bits = UART_DATABITS_8,
            .parity = UART_PARITY_NONE,
            .stop_bits = UART_STOPBITS_1,
            .auto_flow_control = UART_AFCE_DIS,
            .use_fifo = UART_FIFO_EN,
            .tx_fifo_tr_lvl = UART_TX_FIFO_LEVEL_0,
            .rx_fifo_tr_lvl = UART_RX_FIFO_LEVEL_0,
            .intr_priority = 0,
        };
            //Iniitialize UART1
        uart_initialize(UART1, &uart_cfg);
        
    }
    static void disable_uart1()
    {
            uart_disable(UART1);
        
            //Reconfigure UART pins for 4-Wire UART 
        GPIO_ConfigurePin(gpio_uart1_tx.port, gpio_uart1_tx.pin, OUTPUT, PID_UART1_TX, false);
        GPIO_ConfigurePin(gpio_uart1_rx.port, gpio_uart1_rx.pin, INPUT_PULLUP, PID_UART1_RX, false);
        GPIO_ConfigurePin(gpio_uart1_rts.port, gpio_uart1_rts.pin, OUTPUT, PID_GPIO, true);
        GPIO_ConfigurePin(gpio_uart1_cts.port, gpio_uart1_cts.pin, INPUT_PULLUP, PID_UART1_CTSN, false);    
    }
    static void print_me(void)
    {
            arch_set_sleep_mode(ARCH_SLEEP_OFF);
        //Initialize UART1
            enable_uart1();
    #if USER_CFG_ADDRESS_MODE == APP_CFG_ADDR_STATIC
        // Send the BDA
            uart_send(UART1, addr2, (sizeof(addr2)+ 2), UART_OP_BLOCKING);
    #else
            uint32_t bdaddr_msb = (GetWord32(BLE_BDADDRU_REG))&0x1FFFF;
            uint32_t bdaddr_lsb = (GetWord32(BLE_BDADDRL_REG));
            uint8_t addr[6];
            memcpy(&addr2, &bdaddr_lsb, 4);
            memcpy(&addr2[4], &bdaddr_msb, 2);
            uart_send(UART1, addr2, (sizeof(addr2)+ 2), UART_OP_BLOCKING);
    #endif    
        
        
        //Disable UART1 and reconfigure the UART pins for 4-Wire UART
            disable_uart1();
        
            arch_set_sleep_mode(app_default_sleep_mode);
    
    }

    You should also modify the default_app_generate_static_random_addr API on app_default_handlers.c file as shown below:

    extern uint8_t addr2[BD_ADDR_LEN];
    void default_app_generate_static_random_addr(struct bd_addr *addr)
    {
        // Check if the static random address is already generated.
        // If it is already generated the two MSB are equal to '1'
        if (!(addr->addr[BD_ADDR_LEN - 1] & GAP_STATIC_ADDR))
        {
            // Generate static random address, 48-bits
            co_write32p(&addr->addr[0], co_rand_word());
            co_write16p(&addr->addr[4], co_rand_hword());
                
            // The two MSB shall be equal to '1'
            addr->addr[BD_ADDR_LEN - 1] |= GAP_STATIC_ADDR;
        }
            memcpy(&addr2, &addr->addr, BD_ADDR_LEN);
            
    }

    In order for the project to be able to compile, you will have to change the value of the MSG_HEAP_SZ on the da14531_config_advanced.h file:
    #define MSG_HEAP_SZ             (4020)

    Finally, you can call the print_me function whenever you want inside the user_sps_device_dma.c file.
    I called it inside the user_advertise_operation(void). Each time we start advertising, we will initialize briefly UART1 and send the BDA to the Host MCU. The Host MCU should handle the BDA and save it on his side.
    Please also refer on the dsps_uart1_bda.mp4 video as well.

     

    Note: The implementation could change depending on the value of the USER_CFG_ADDRESS_MODE macro.
    Note2: If you want the Host MCU to be able to request the BDA from the DA14531 via a command, that would require a different implementation and it will need to reduce the Heap size more that could affect the performance of the SPS SDK.

  • Hi,

    Thank you for reply,

    can you resend the post as the previous post content was overlapped as shown below:

    Regards,

    Laxmi Narayana.

  • Hi Laxmi,

    Thank you for the reply.
    Please refer here: DA14531 sending BD address after receiving certain command or custom string in serial port service - Bluetooth Low Energy - Wireless Connectivity - Renesas Engineering Community

    It will be hard to fully implement multiple AT commands as it is in CodeLess SDK but of course you can try it out on your side. 


    Best Regards,
    OV_Renesas

  • Hi OV,

    Thank you for reply,

    The requirement what i have is when BT module is not connected with Application, the host MCU will send some BT parameter to save in SPI Flash.

    So, for this i require the flag where it tells When BT module connects to Android App and when BT module disconnected with Android Application.

    Regards,

    Laxmi Narayana.

  • Hi Laxmi,

    Thank you for the reply.

    So, for this i require the flag where it tells When BT module connects to Android App and when BT module disconnected with Android Application.

    You can do that on the callback functions:



    The requirement what i have is when BT module is not connected with Application, the host MCU will send some BT parameter to save in SPI Flash.

    When you are not connected, the UART is automatically shut down. You will have to change that but keep in mind that it will affect the current consumption.

    Best Regards,
    OV_Renesas

  • Hi OV,

    Thank you for reply,

    When you are not connected, the UART is automatically shut down. You will have to change that but keep in mind that it will affect the current consumption.

    I want to use UART communication when BT module not connected to Android App also. how can i do that.

    Please suggest.

    Regards,

    Laxmi Narayana.

  • Hi Laxmi,

    Thank you for the reply.
    Please keep in mind that the SPS SDK was not designed to have the UART enabled all the time. You can test this on your side.
    UART is initialized when we establish a connection, please refer on the user_on_connect callback function

    You can see that we call the dma_uart_on_connect function:

    void dma_uart_on_connect(void){
        dma_uart.tx_size = DEFAULT_TX_SIZE;
        if( app_default_sleep_mode == ARCH_SLEEP_OFF ){
            dma_uart_sps_init(cfg_uart_sps_baudrate, 3);
            dma_uart_rx_activate();
            dma_uart_assert_rts();
        }   
    }


    You could try to remove the dma_uart_on_connect function from the user_on_connection callback and set it on app_on_init callback function. 
    You should keep in mind that when we disconnect the UART will be disabled as well.


    Best Regards,
    OV_Renesas

  • Hi OV,

    Thank you for reply,

    You could try to remove the dma_uart_on_connect function from the user_on_connection callback and set it on app_on_init callback function. 

    I Tried the same, still not able to establish UART communication which App is disconnected.

    Can you help me in this implementation?

    Regards,

    Laxmi Narayana 

  • Hi Laxmi,

    Thank you for the reply.

    Please take above implementation as reference. You can use this to keep UART initialized when you are not connected. On user_on_connection you can disable the UART and let dma_uart_on_connect to initialize it correctly for the Serial Port Service feature.

    Best Regards,
    OV_Renesas

  • Hi OV,

    Thank you for supporting, 

    when Application not connected to BT module i enabled uart in function periph_init() as shown in below 

    Initially i tried to do loopback test to verify UART Tx and Rx. but it didn't worked for me.

    So, I tried to send fixed string ACK. which i able receive the string for first 3 times and further receiving junk bytes continuously as shown below.

     

    Please help me in fixing this issue.

    Regards,

    Laxmi Narayana.