STM32 and NRF24l01
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();
}
