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

ask about this BUG the SPIM: An additional byte is clocked out when RXD.MAXCNT = 1

Dear nordic employee

when I use the spim to send 1 byte address to read it's value(4 bytes)

nrf_drv_spi_transfer(&spi,headerBuffer,(uint8_t)headerLength,readBuffer,(uint8_t)readlength);    headerLength=1;      readlength=4;

I get the problem like the title says

I try to solve it

so I DO like this :spi_pan58_workaround_sdk12.zip(which Referred here

but when I try to read 4byte data(with 1 byte address write),the result is 00 00 00 00(it should be 12 02 33 44 )

where is wrong ?

thank you!

  • should I put the code between the start and end?

    and where should I put these all source code?

    thank you

  • It should be shown in the main.c file in the spi_pan58_workaround_sdk12.zip in the post you linked to. Please take a look at that file.

    I.e.

    Add this with the other defines:

    // ### Workaround Section Start ###
    #include "nrf_drv_ppi.h"
    #include "nrf_drv_gpiote.h"
    // ### Workaround Section End   ###
    
    // ### Workaround Section Start ###
    static nrf_ppi_channel_t ppi_channel;
    //Dummy handler
    void in_pin_handler( nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        //Do nothing
    }
    // ### Workaround Section End   ###
    

    in spi_event_handler, add this at right after NRF_DRV_SPI_EVENT_DONE

     // ### Workaround Section Start ###
    
    // Disable the PPI channel
    err_code = nrf_drv_ppi_channel_disable(ppi_channel);
    APP_ERROR_CHECK(err_code);
    
    // Disable a GPIOTE output pin task.
    nrf_drv_gpiote_in_event_disable(SPI_SCK_PIN);
    
    // ### Workaround Section End   ###
    

    after APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL)); in main(), you add this:

    // ### Workaround Section Start ###
        
         uint32_t err_code;
        
         NRF_SPIM_Type * p_spim = spi.p_registers;
        
        //Initialize GPIOTE and PPI drivers for the workaround
        
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
        
        // Initializes the GPIOTE channel so that SCK toggles generates events
        nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
                err_code = nrf_drv_gpiote_in_init(SPI_SCK_PIN, &config, in_pin_handler);
                APP_ERROR_CHECK(err_code); 
            
        err_code = nrf_drv_ppi_init();
        APP_ERROR_CHECK(err_code);
        
        // Allocate first unused PPI channel 
        err_code = nrf_drv_ppi_channel_alloc(&ppi_channel);
        APP_ERROR_CHECK(err_code);
        
        // Assign the PPI channel to the SCK pin
        err_code = nrf_drv_ppi_channel_assign(ppi_channel,
                                            nrf_drv_gpiote_in_event_addr_get(SPI_SCK_PIN),
                                            (uint32_t)&p_spim->TASKS_STOP);
        APP_ERROR_CHECK(err_code);
    
    
    // ### Workaround Section End   ###    
    

    Then use the function spi_send_recv when you want to send 1 byte data

  • thank you for your code

    but I have two more questions

    1、I haven't see any difference between your code and the spi_pan58_workaround_sdk12.zip(about the spi),so what do you mean spi_pan58_workaround_sdk12.zip is just for sdk12?

    what is the difference between the spi_pan58_workaround_sdk12.zip and you code above?

    2、today I just try init like this : nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL);

    haven't added the PPI and gpiote code yet

    only add the spi_event_handler

    the result turn to be :00 00 00 00(right is 12 02 33 44),even the spi_event_handler is NULL Like

    this:void spi_event_handler(nrf_drv_spi_evt_t const * p_event,void * p_context) { //do nothing }

    when I remove the spi_event_handler,like this :nrf_drv_spi_init(&spi, &spi_config, NULL, NULL),the result is turn to be FF 12 02 33

    my question is:why the spi_event_handler can influence the result

    thank you!

  • @Sigurd。 hi,can you hear me? I need your help ,thank you

    1. The example project was for SDK 12. I.e. if you just copy the example to SDK 14, it will not compile. So you need to port the code to the SDK 14 SPI example.

    2. Your init function looks correct. You need to add the PPI and GPIOTE code for the fix to work. In the example project with the fix, we disable the PPI and GPIOTE in the spi_event_handler when we get the event NRF_DRV_SPI_EVENT_DONE.

Related