cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 and NRF24l01

ThienNguyen0301
Associate II

Hello everyone
I make  SPI communication between Stm32f411 and module NRF24l01.

I have written a function to transfer data from stm32 to Nrf24l01, and read data from Nrf24l01.

Everyone help me to edit code because this is my first time using this protocol

 

void nrf24_WriteReg (uint8_t Reg, uint8_t Data)

{

uint8_t buf[2];

buf[0] = Reg|1<<5;

buf[1] = Data;

 

// Pull the CS Pin LOW to select the device

CS_Select();

 

HAL_SPI_Transmit(NRF24_SPI, buf, 2, 1000);

 

// Pull the CS HIGH to release the device

CS_UnSelect();

}

 

//write multiple bytes starting from a particular register

void nrf24_WriteRegMulti (uint8_t Reg, uint8_t *data, int size)

{

uint8_t buf[2];

buf[0] = Reg|1<<5;

// buf[1] = Data;

 

// Pull the CS Pin LOW to select the device

CS_Select();

 

HAL_SPI_Transmit(NRF24_SPI, buf, 1, 100);

HAL_SPI_Transmit(NRF24_SPI, data, size, 1000);

 

// Pull the CS HIGH to release the device

CS_UnSelect();

}

 

 

uint8_t nrf24_ReadReg (uint8_t Reg)

{

uint8_t buf[1];

buf[0]=Reg|0<<5;

uint8_t data;

 

 

// Pull the CS Pin LOW to select the device

CS_Select();

 

HAL_SPI_Transmit(NRF24_SPI, buf[0], 1, 100);

HAL_SPI_Receive(NRF24_SPI, &data, 1, 100);

 

// Pull the CS HIGH to release the device

CS_UnSelect();

 

return data;

}

 

 

/* Read multiple bytes from the register */

void nrf24_ReadReg_Multi (uint8_t Reg, uint8_t *data, int size)

{

// Pull the CS Pin LOW to select the device

CS_Select();

 

HAL_SPI_Transmit(NRF24_SPI, &Reg, 1, 100);

HAL_SPI_Receive(NRF24_SPI, data, size, 1000);

 

// Pull the CS HIGH to release the device

CS_UnSelect();

}

 

2 REPLIES 2
KDJEM.1
ST Employee

Hello @ThienNguyen0301 ,

 

Could you please give more detail about the issue? Do you facing an issue?

Are you able to transmit and/or to receive data?

To start with SPI protocol, I advise you to refer to this wiki: Getting started with SPI - stm32mcu.

 

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Pavel A.
Evangelist III

Everyone help me to edit code because this is my first time using this protocol

Here you can find help with your stm32 project.