nRF5340 SPI Master example code

Hi,

I tried configure and run SPI master interface on nRF 5340 DK board  using several examples for nRF 5340 but I had some compile errors or they did not work. Is there any example that will allow me to run SPI  master interface at 16MHz or more using the most recent SDK?

Could somenoe point me to a solution for this problem.

Thank you

Parents
  • Hi Derek,

    I attempted to use your example and combine it with my code. I need only master SPI driver since my peripheral devices are ADC and DAC. For now, I am trying to make ADC work.  I am using timer to start SPI transmit and receive operations. Eventually I will need two SPI master interfaces because ADC and DAC must operate simultaneously. 

    I am able to run timer at desired frequency and initialize SPI interface without any error message but every time when I attempt to send or receive data using SPI the board (nRF5340 DK) reboots.

    Zephyr RTOS is new to me, and I have difficulties to find what is the cause of the problem.

    Below is the debug terminal screenshot and my link to my code is here.

      

  • Hi there,

    Are you able to run the example without any modifications? And what modifications did you do to the project? The program is asserting here, is there a chance that you're trying to call the adc_sample from the timer callback as in this case?

    regards

    Jared 

  • Hi Jared,

    No, I am trying to call spi_write_test(). I am not attempting to use SOC integrated ADC. I am using an external ADC. Please see lines 527-535 in main.c.

    I added timer0 functionality and SPI master to the central_and_perpheral_hr example. Moreover, I will need two master SPI interfaces. One for external DAC and one for external ADC. The ADC and the DAC will operate at a same time.

    Timer0 elapsed event works as expected but every time when spi_write_test() is called the soc resets.

    void timer0_elapsed(struct k_timer *timer_id)
    {

    value = !value;
    dk_set_led(DK_LED2, value);
    //spi_write_test_msg();
    spi_write_test();

    }

    Thank you,

    Franci 

  • Hi,

    Ok, but I think the end result is somewhat the same as you're calling it in the timer handler. Could you instead try to offload it to a work queue every time the callback handler is called?

    regards
    Jared 

Reply Children
Related