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!

Parents
  • Hi,

    • What SDK version are you using ?
    • What was the result of the read operation before you added the workaround ? Did you get 00 00 00 00 before you added the workaround also? or did you get something else?
  • 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

Reply
  • 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

Children
No Data
Related