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

SPIM EasyDMA - sending and reading one byte

Hello, I am developing custom HAL driver for SPI in NRF52 (PCA10040). The problem is that using the EasyDMA MAXCNT registers value must be between 1...255. It implicates that sending and receiving 1 Byte of data is impossible. SPIM alway clocks 16bit of data on the SPI bus. I configured the TXD.MAXCNT/RXD.MAXCNT to 0 for receiving/sending, but this solution led me into undefined behavior of SPIM peripheral.

I have a question whether it is possible to clock 1 byte of data using EasyDMA in SPIM.

Parents
  • I looked after nrf_drv_spi_transfer() function. There is simple setting of DMA registers as in my write function. Btw. I know the data should be in RAM section (I made a test - I located the transmit DMA buffer in flash and no error occured).

    Example provided below for reading one byte clocks 16bits of data:

    eventClear(Event::END);
    spi.TXD.PTR = reinterpret_cast<uint32_t>(&write);
    spi.TXD.MAXCNT = 0;    
    spi.RXD.PTR = reinterpret_cast<uint32_t>(&buffer); 
    spi.RXD.MAXCNT = 1;
    spi.ORC = 0;
    taskTrigger(Task::START);
    

    Pertaining to the datasheet above solution shouldn't be used because of 0 written to MAXCNT register. With ones in MAXCNT registers the situation is the same.

    My most recent test shows that calling above function (with 1 in TX MAXCNT and RX MAXCNT) clocks alternately 8bits and 16bits (16bits just after enabling SPIM) :) How to force the peripheral to send only 8bit?

Reply
  • I looked after nrf_drv_spi_transfer() function. There is simple setting of DMA registers as in my write function. Btw. I know the data should be in RAM section (I made a test - I located the transmit DMA buffer in flash and no error occured).

    Example provided below for reading one byte clocks 16bits of data:

    eventClear(Event::END);
    spi.TXD.PTR = reinterpret_cast<uint32_t>(&write);
    spi.TXD.MAXCNT = 0;    
    spi.RXD.PTR = reinterpret_cast<uint32_t>(&buffer); 
    spi.RXD.MAXCNT = 1;
    spi.ORC = 0;
    taskTrigger(Task::START);
    

    Pertaining to the datasheet above solution shouldn't be used because of 0 written to MAXCNT register. With ones in MAXCNT registers the situation is the same.

    My most recent test shows that calling above function (with 1 in TX MAXCNT and RX MAXCNT) clocks alternately 8bits and 16bits (16bits just after enabling SPIM) :) How to force the peripheral to send only 8bit?

Children
No Data
Related