Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

HELP with HAL_SPI_Transmit() - in nRF24L01 Library Port for STM32F103C8

Status
Not open for further replies.

igtaba

Newbie level 2
Newbie level 2
Joined
Oct 22, 2018
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
40
Hello people, I'm in need of help with SPI for a university project. Please bear in mind that I am a complete newbie to programming MCU and SPI, and sorry for my bad English (Spanish speaker) .

I'm trying to port a library for the nRF24L01 module to use with a STM32F103C8 (blue pill module) programming in uVision 5 using HAL Libraries, but I have tried a lot of libraries that did not work for my MCU or HAL or are to hard to port; Since I found Lonely Wolf's library in GitHub and I'm trying to port it because is well documented and separates the hardware dependent of the non-hardware dependent parts of code in a clear way, the problem I face is the changing of the SPI (He uses ST STD Peripheral Lib) to Hal libraries. I need to do this because most of my code is base around the HAL libraries, but I cant to use the 2 at the same time.
The librarie uses the next function to send the data from the MCU to the RF module:
HTML:
// Low level SPI transmit/receive function (hardware depended)
// input:
//   data - value to transmit via SPI
// return: value received from SPI
uint8_t nRF24_LL_RW(uint8_t data) {/*
	 // Wait until TX buffer is empty
	while (SPI_I2S_GetFlagStatus(nRF24_SPI_PORT, SPI_I2S_FLAG_TXE) == RESET);
	// Send byte to SPI (TXE cleared)
	SPI_I2S_SendData(nRF24_SPI_PORT, data);
	// Wait while receive buffer is empty
	while (SPI_I2S_GetFlagStatus(nRF24_SPI_PORT, SPI_I2S_FLAG_RXNE) == RESET);

	// Return received byte
	return (uint8_t)SPI_I2S_ReceiveData(nRF24_SPI_PORT);*/
}

and this is the function that I'm trying to replace it with

HTML:
extern hspi1; //This is done at the top of the .c file and I understand that this make possible to call
//the hspi1 generated with the CubeMX in the main.c with the Init values for the SPI ports

// Low level SPI transmit/receive function (hardware depended)
// input:
//   data - value to transmit via SPI
// return: value received from SPI
uint8_t nRF24_LL_RW(uint8_t dataIn) {
	uint8_t dataOut;
	HAL_SPI_TransmitReceive(&hspi1, &dataIn, &dataOut, 1,1000 );
        return dataOut;
}

Is this implementation of the HAL function ok? would actually work?

The other problem I have is how to use this actual library to make a working transceiver between 2 MCU and a pair of RF module, but first I need help to make the library work

Thanks in advance
 

Thanks for your SPI library, but he problem is that your library as well the one that I'm porting, requieres ST std peripheral libraries and startup, and either that and HAL from CubeMX doesn't work or I'm to stupid to make it work (this maybe the case)

There isn't a way to adapt HAL SPI library to do the SPI communication on this RF module?

The update is that las night the function I'm trying to use to replace the std peripheral library is now looking like this:

HTML:
#include "nrf24_hal.h"

extern SPI_HandleTypeDef hspi1;

uint8_t dataOut;

// Low level SPI transmit/receive function (hardware depended)
// input:  data - value to transmit via SPI
// return: value received from SPI
uint8_t nRF24_LL_RW(uint8_t data) {
	while (__HAL_SPI_GET_FLAG(&hspi1, SPI_FLAG_TXE) == RESET);

	HAL_SPI_Transmit(&hspi1, &data, 1,100 );
	
	while (__HAL_SPI_GET_FLAG(&hspi1, SPI_FLAG_RXNE) == RESET);
	
	HAL_SPI_Receive(&hspi1, &dataOut, 1,100);
	
	return dataOut;
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top