This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF52833 SDK 16.0.0 Problems initialization SPI Master

Hello everyone!

I am trying to add a SPI Master instance for my custom PCB, im using spi example as reference but im having a specific problem, and it is that the program dont pass the SPI initialization code line (not even return a error code).  

My code look like this:

static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(0); 

void nrf_spi_init(void){

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = SPI_CS;
    spi_config.miso_pin = SPI_MISO;
    spi_config.mosi_pin = SPI_MOSI;
    spi_config.sck_pin  = SPI_SCLK;
    
    turn_on_led(RGB_LEDS_B);
    ret_code_t err_code =  nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL);
    switch(err_code){
        case NRF_SUCCESS:
            turn_on_led(RGB_LEDS_G);
            break;
        default:
            turn_on_led(RGB_LEDS_R);
            break;
    }
    
    
}

As you can see, i am using a RGB Leds to check what part of the code is executing well. The think is that the code compile well, flash well, but never pass the  "nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL);" line. (The LED keep BLUE and not even the Green or Red LED turns on).

I have the next definitions on sdk_config.h:
#ifndef SPI_ENABLED
#define SPI_ENABLED 1
#endif

#ifndef SPI0_ENABLED
#define SPI0_ENABLED 1
#endif

#ifndef SPI1_ENABLED
#define SPI1_ENABLED 0
#endif


#ifndef NRFX_SPI_ENABLED
#define NRFX_SPI_ENABLED 1
#endif

#ifndef NRFX_SPI0_ENABLED
#define NRFX_SPI0_ENABLED 1
#endif

#ifndef NRFX_SPI1_ENABLED
#define NRFX_SPI1_ENABLED 0
#endif

#ifndef NRFX_SPIM_ENABLED
#define NRFX_SPIM_ENABLED 0
#endif

#ifndef NRFX_SPIM0_ENABLED
#define NRFX_SPIM0_ENABLED 0
#endif

#ifndef NRFX_SPIM1_ENABLED
#define NRFX_SPIM1_ENABLED 0
#endif

I literally try every combination of this Defines ( SPIM enabled, SPI+SPIM, Only SPIM, etc) But nothing works. If someone have gone through something similar it will be very usefull for me, i will really appretiace the help.

Regards.

  • Hello,

    Have you tried stepping through your code? What happens when you execute line 12 in your snippet? Does it return? Using a debugger and actually checking what happens inside this function can be useful if it doesn't return at all.

    Not knowing your HW or how the turn_on_led() function works, I don't know how to interpret that. You checked that calling turn_on_led(RGB_LEDS_B) and then turn_on_led(RGB_LEDS_G) actually turns on the green LED even if the red was turned on first?

    Do you have a debugger that you can use to step through the code?

    Best regards,

    Edvin

  • Hi Edvin TY for youy answer, i manage to solve the problem. It was that i migrate my project from nrf52832 to nrf52833, and i was missing a defining on the makefile, specifically i keep the define "-DNRF52" instead of "-DNRF52833", that make that the whole port 1 of the mcu out of range for the code. So how my SPI pins are in the port 1 at the moment i try to initialize them it seem like everything crash. Hope this can help someone in the future.

Related