cancel
Showing results for 
Search instead for 
Did you mean: 

Hi I am implementing a nrf24l01 driver with the use of stm32F4 the SPI transmit and receive works with the polling method yet not with DMA method.I already configured the DMA on cube mx and IAR WORKBENCH this is the code part i put the dma as cmnt

atoua.1
Associate

//3. Read single byte from a register

uint8_t NRF24_read_register(uint8_t reg)

{

   uint8_t spiBuf[3];

   uint8_t retData;

   //Put CSN low

   NRF24_csn(0);

   //Transmit register address

   spiBuf[0] = reg&0x1F;

   HAL_SPI_Transmit(&nrf24_hspi, spiBuf, 1, 100);

     // HAL_SPI_Transmi_DMA(&nrf24_hspi, spiBuf, 1);

   //Receive data

   HAL_SPI_Receive(&nrf24_hspi, &spiBuf[1], 1, 100);

      // HAL_SPI_Receive_DMA(&nrf24_hspi, &spiBuf[1], 1);

   retData = spiBuf[1];

   //Bring CSN high

   NRF24_csn(1);

   return retData;

}

//4. Read multiple bytes register

void NRF24_read_registerN(uint8_t reg, uint8_t *buf, uint8_t len)

{

   uint8_t spiBuf[3];

   //Put CSN low

   NRF24_csn(0);

   //Transmit register address

   spiBuf[0] = reg&0x1F;

   //spiStatus = NRF24_SPI_Write(spiBuf, 1);

   HAL_SPI_Transmit(&nrf24_hspi, spiBuf, 1, 100);

       // HAL_SPI_Transmi_DMA(&nrf24_hspi, spiBuf, 1);

   //Receive data

   HAL_SPI_Receive(&nrf24_hspi, buf, len, 100);

       HAL_SPI_Receive_DMA(&nrf24_hspi, buf, len);

   //Bring CSN high

   NRF24_csn(1);

}

//5. Write single byte register

void NRF24_write_register(uint8_t reg, uint8_t value)

{

   uint8_t spiBuf[3];

   //Put CSN low

   NRF24_csn(0);

   //Transmit register address and data

   spiBuf[0] = reg|0x20;

   spiBuf[1] = value;

   HAL_SPI_Transmit(&nrf24_hspi, spiBuf, 2, 100);

       //HAL_SPI_Transmit_DMA(&nrf24_hspi, spiBuf, 2);

   //Bring CSN high

   NRF24_csn(1);

}

//6. Write multipl bytes register

void NRF24_write_registerN(uint8_t reg, const uint8_t* buf, uint8_t len)

{

   uint8_t spiBuf[3];

   //Put CSN low

   NRF24_csn(0);

   //Transmit register address and data

   spiBuf[0] = reg|0x20;

   HAL_SPI_Transmit(&nrf24_hspi, spiBuf, 1, 100);

       //HAL_SPI_Transmit_DMA(&nrf24_hspi, spiBuf, 1);

   HAL_SPI_Transmit(&nrf24_hspi, (uint8_t*)buf, len, 100);

       //HAL_SPI_Transmit_DMA(&nrf24_hspi, (uint8_t*)buf, len);

   //Bring CSN high

   NRF24_csn(1);

}

0 REPLIES 0