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

ble_app_uart + spi only works with connected J-Link

Hi,

I am working on the ble_app_uart which should forward data to the SPI port of the nRF52832.

It all works fine while the J-Link is connected. If I want to run my application without attached debugger it does not work. It gets stuck in SPI transfer while waiting for the Slave to pull the busy pin to low in a while loop.

I attached a logic analyser and the SPI looks like in debugging mode, till the nRF52832 waits for the slave to respond.

But why does the Slave not respond to the transmitted configuration data? If I run the nRF52832 without J-Link?

I read many posts in the devzone but I dont know where to start.

I am working with SES and nRF5_SDK_15.2.0.

I adjusted the project configuration in SES to both Debug and Release to the same:

Code > Code Generation > Optimization Level > None

Code > Code Generation > Debugging Level > Level 3

Are there any other things to consider? Power mode? CMSIS / sdk_config.h settings?

Code Snippet:

int main(void)
{
    bool erase_bonds;

    // Initialize.
    uart_init();

    //SPI init
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.mode = NRF_DRV_SPI_MODE_0;
    spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
    spi_config.ss_pin   = SPI_SS_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;
    //spi_config.irq_priority = 0;
    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));
 
    //Slave reset pin
    nrf_gpio_cfg_output(RST_PIN);
    nrf_gpio_pin_set(RST_PIN);
    //Slave busy pin
    nrf_gpio_cfg_input(BUSY_PIN, NRF_GPIO_PIN_NOPULL);

    //Original code...
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();


    // Start execution.
    printf("UART started.\r\n");
    NRF_LOG_INFO("Debug logging for UART over RTT started.");

    /
    printf("SPI Test...\r\n");
    if (SLAVE_Init() != 0) {
    } else {      
        SLAVE_SendData();
        SLAVE_Sleep();
    } 

    printf("Start advertising\r\n");
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        //If flag is set from nus_data_handler, forward it...
        if(start_spi_tx_flag)
        {
            printf("SPI Test...\r\n");
            if (SLAVE_Init() != 0) {
            } else {      
                SLAVE_SendData();
                SLAVE_Sleep();
            } 
            start_spi_tx_flag = false;
        }	
        idle_state_handle();
    }
}

Best regards

  • You need to scope your i/o lines with a digital logic analyzer and compare the two states. 

  • It all works fine while the J-Link is connected

    What, exactly, do you mean by "connected" ?

    Do you just mean when the cable is physically in place, but the JLink is not in use?

    Or do you mean it only works when run under the debugger?

    Or something else?

    Are you using a Nordic board, or something else?

    What sensor is it? How is it connected to the board? Are you sure that there is a good ground connection between sensor & board?

  • Yes, I did this the signals looks good.

    Working (with J-Link connected): The slave needs about 8 seconds to process the data and respond.

    Not working (without J-Link connected): The slave could not interpret or process the data. Why does this depend on J-Link?

    I just analyzed the last data which was transmitted before it get stuck.

    My last data command should be 0x12 (1 Byte) but after that I get an additionally byte with 0xFF. In both cases. But this should not be transfered.

    Is there a 16 Bit SPI mode? Or something like that?

  • >  What, exactly, do you mean by "connected" ?

    With connected I mean that I choose "Target" > "Connect J-Link"  in the SES IDE.

    If it is disconnected and I choose "Target" > "Download ble_app..." and push the reset button, it stucks in the SPI routine waiting for the slave to respond after 4kByte data transmission. Then, if I connect J-Link and push the reset button again it starts working fine.

    > Or do you mean it only works when run under the debugger?

    So I think the debugger is running even if I dont step through the code.

    > Do you just mean when the cable is physically in place, but the JLink is not in use?

    The USB cable is always plugged in.

  • > Are you using a Nordic board, or something else?

    I am using the Nordic DK. On my custom PCB the behavior is the same.

    > What sensor is it? How is it connected to the board? Are you sure that there is a good ground connection between sensor & board?

    I am controlling an e-paper display with 4kByte imagedata.

    I'll check the GND connection. I just soldered 10cm of wire between the two devices.

Related