This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Understanding the API calls.

nRf Gurus, I need your help!
It is very hard for me to understand top level configuration of the soft devices and overall mentality. I am sure it will be very easy and convenient as soon as I will understand how to interact with these soft-devices and modems. Can anyone PLEASE(!) present a bare code in a single "main" function and "includes'', if any needed.
The goal is to start the device, send "AT+CFUN?" and read the result back into variable with API or using AT-library.
This will be a great help to understand how everything else is structured over here.

Parents
  • Hi,

     

    The goal is to start the device, send "AT+CFUN?" and read the result back into variable with API or using AT-library.

     You can use the at_cmd_write() function for that. The result will be read back into a buffer that you pass to the function.

     

    Can anyone PLEASE(!) present a bare code in a single "main" function and "includes'', if any needed.

     You can use most samples in the SDK. This one is quite simple.

  • Thank you for your support.
    I got over the AT_Library and modified the sample to check both, "at_cmd_write" and "at_cmd_write_with_callback" functions. For the debugging convenience i used "spagetti" style instead of looping and still need a small help with callbacks. While "at_cmd_write" is working great, it looks like handler routine for "at_cmd_write_with_callback" ("responce_handler" in this case) does not have IRQ priority and not getting called while code is running.
    As you can see on the terminal, "at_cmd_write" replied right back, but handler of "at_cmd_write_with_callback" waited until "main" got through and only then kicked in. It is really important for me to properly arrange the sequence of the logging in to the server, what am I doing wrong?
    How can I get the handler to be a priority interrupt?

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    #include <zephyr.h>
    #include <stdio.h>
    #include <drivers/uart.h>
    #include <string.h>
    #include <drivers/clock_control.h>
    #include <drivers/clock_control/nrf_clock_control.h>
    
    //enum at_cmd_state at_state;
    
    /**@brief Recoverable modem library error. */
    
    
    
    
    void nrf_modem_recoverable_error_handler(uint32_t err)
    {
    	printk("Modem library recoverable error: %u\n", err);
    }
    
    /* To strictly comply with UART timing, enable external XTAL oscillator */
    void enable_xtal(void)
    {
    	struct onoff_manager *clk_mgr;
    	static struct onoff_client cli = {};
    
    	clk_mgr = z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
    	sys_notify_init_spinwait(&cli.notify);
    	(void)onoff_request(clk_mgr, &cli);
    }
    
    static void responce_handler(const char* response){
        if(strlen(response) > 0){
            printk("AT recv:\t%s",response);}
    }
    
    void main(void)
    {
            int err;
            char rback[20];
    	enable_xtal();
            nrfx_systick_init();//Sam
    	printk("The AT host sample started\n");
            nrfx_systick_delay_ms(1000);  
               
            printk("Sending AT+CFUN=1\n");
            if((err = at_cmd_write_with_callback("AT+CFUN=1",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(10);
            printk("Sending AT+CFUN?\n");
            //if((err = at_cmd_write_with_callback("AT+CFUN?",&responce_handler)) !=0)
            if((err = at_cmd_write("AT+CFUN?",&rback,sizeof(rback),NULL) !=0))
              {printk("Return: Error\n", err);}
            else 
              {printk(rback,"\n");
                printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(1000); 
            /*******************************************/
            printk("Requesting MFG ID\n");
            if((err = at_cmd_write_with_callback("AT+CGMI?",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(10);
            /*******************************************/
            printk("Requesting Temp\n");
            if((err = at_cmd_write_with_callback("AT%XTEMP?",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(1000);
            /*******************************************/
            printk("Sending AT+CFUN=0\n");
            if((err = at_cmd_write_with_callback("AT+CFUN=0",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(10);
                    printk("Sending AT+CFUN?\n");
            if((err = at_cmd_write_with_callback("AT+CFUN?",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(10);
                  
    }
    



    The AT host sample started
    Sending AT+CFUN=1
    Return: OK
    Sending AT+CFUN?
    +CFUN: 1
    Return: OK
    Requesting MFG ID
    Return: OK
    Requesting Temp
    Return: OK
    Sending AT+CFUN=0
    Return: OK
    Sending AT+CFUN?
    Return: OK
    AT recv:%XTEMP: 27
    AT recv:+CFUN: 0

Reply
  • Thank you for your support.
    I got over the AT_Library and modified the sample to check both, "at_cmd_write" and "at_cmd_write_with_callback" functions. For the debugging convenience i used "spagetti" style instead of looping and still need a small help with callbacks. While "at_cmd_write" is working great, it looks like handler routine for "at_cmd_write_with_callback" ("responce_handler" in this case) does not have IRQ priority and not getting called while code is running.
    As you can see on the terminal, "at_cmd_write" replied right back, but handler of "at_cmd_write_with_callback" waited until "main" got through and only then kicked in. It is really important for me to properly arrange the sequence of the logging in to the server, what am I doing wrong?
    How can I get the handler to be a priority interrupt?

    /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    #include <zephyr.h>
    #include <stdio.h>
    #include <drivers/uart.h>
    #include <string.h>
    #include <drivers/clock_control.h>
    #include <drivers/clock_control/nrf_clock_control.h>
    
    //enum at_cmd_state at_state;
    
    /**@brief Recoverable modem library error. */
    
    
    
    
    void nrf_modem_recoverable_error_handler(uint32_t err)
    {
    	printk("Modem library recoverable error: %u\n", err);
    }
    
    /* To strictly comply with UART timing, enable external XTAL oscillator */
    void enable_xtal(void)
    {
    	struct onoff_manager *clk_mgr;
    	static struct onoff_client cli = {};
    
    	clk_mgr = z_nrf_clock_control_get_onoff(CLOCK_CONTROL_NRF_SUBSYS_HF);
    	sys_notify_init_spinwait(&cli.notify);
    	(void)onoff_request(clk_mgr, &cli);
    }
    
    static void responce_handler(const char* response){
        if(strlen(response) > 0){
            printk("AT recv:\t%s",response);}
    }
    
    void main(void)
    {
            int err;
            char rback[20];
    	enable_xtal();
            nrfx_systick_init();//Sam
    	printk("The AT host sample started\n");
            nrfx_systick_delay_ms(1000);  
               
            printk("Sending AT+CFUN=1\n");
            if((err = at_cmd_write_with_callback("AT+CFUN=1",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(10);
            printk("Sending AT+CFUN?\n");
            //if((err = at_cmd_write_with_callback("AT+CFUN?",&responce_handler)) !=0)
            if((err = at_cmd_write("AT+CFUN?",&rback,sizeof(rback),NULL) !=0))
              {printk("Return: Error\n", err);}
            else 
              {printk(rback,"\n");
                printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(1000); 
            /*******************************************/
            printk("Requesting MFG ID\n");
            if((err = at_cmd_write_with_callback("AT+CGMI?",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(10);
            /*******************************************/
            printk("Requesting Temp\n");
            if((err = at_cmd_write_with_callback("AT%XTEMP?",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(1000);
            /*******************************************/
            printk("Sending AT+CFUN=0\n");
            if((err = at_cmd_write_with_callback("AT+CFUN=0",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(10);
                    printk("Sending AT+CFUN?\n");
            if((err = at_cmd_write_with_callback("AT+CFUN?",&responce_handler)) !=0)
            { printk("Return: Error\n", err);}
            else 
              {printk("Return: OK\n", err);}
            nrfx_systick_delay_ms(10);
                  
    }
    



    The AT host sample started
    Sending AT+CFUN=1
    Return: OK
    Sending AT+CFUN?
    +CFUN: 1
    Return: OK
    Requesting MFG ID
    Return: OK
    Requesting Temp
    Return: OK
    Sending AT+CFUN=0
    Return: OK
    Sending AT+CFUN?
    Return: OK
    AT recv:%XTEMP: 27
    AT recv:+CFUN: 0

Children
Related