Proper use of the HAL library for SPI communications.
Proper use of the HAL library for SPI communications.
OK, first, I am very new to this and I am slowly learning as I go.
The project I am working on is a radio beacon in the 430MHz range. I have a Nucleo-F446RE board and a RFM23B transceiver module. I am wanting to control the radio via SPI. Following a YouTube video to use SPI I have the following lines of code
uint8_t spiReadRegister(uint8_t address)
{
uint8_t spiTxBuf[2], spiRxBuf[2];
uint8_t result;
spiRxBuf[0] = address;
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); //Bring nSEL low
HAL_SPI_Receive(&hspi1, spiRxBuf, 1, 50); // read 1 byte of data, wait 50usec
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET); //Bring nSEL high
result = spiRxBuf;
return(result);
}the code in is a separate src file "SPI.c" and I get the following error
"'hspi1' undeclared (first use in this function)" for the line "HAL_SPI_Receive(&hspi1, spiRxBuf, 1, 50); // read 1 byte of data, wait 50usec"
Now if I put the same block of code into the main.c file it has no error
What am I doing wrong??
Thanks
Rusty
