2015-10-09 06:34 AM
Hello
We are currently switching from the STD library to the HAL library. Personally I'm not very pleased with that, but due to upcoming projects with F7 MCU we are mandatory to learn to use the HAL Library. We are designing a driver for the RFM69 Radio module. To set the RFM69 to our needs we need to send a lot of commands trough SPI. This is the point where strange things happen. Sometimes the Microcontroller sends the data right, the other times we get a hardfault error. This is the part where the problems begin:void
Rfm69_Write_Reg(uint8_t address, uint8_t value)
{
reg[0] = value;
reg[1] = address | 0x80;
HAL_SPI_Transmit(&hspi1, (uint8_t *)reg, 1, 1000);
}
The value 1 is because of the fact we set the SPI to 16 bit.
The function Rfm69_write_Reg() is called multiple times at initialization of the RFM69 module:
void
Rfm69_Init(
void
)
{
uint8_t i;
Rfm69_Reset();
for
( i = 0; i <
sizeof
(rfm69_base_config) / 2; i++)
{
Rfm69_Write_Reg(rfm69_base_config[i][0], rfm69_base_config[i][1]);
// check = Rfm69_Read_Reg(rfm69_base_config[i][0]);
}
}
But most of the times we get a Hardfault Handler. The strange thing is that when we uncomment the: check = Rfm69_Read_reg(rfm69_base_config[i][0]); line
The program is working correctly.
Does somebody sees the problem or has encountered the same problem?
My sincerly
#hal #spi #hardfault #m0
2015-10-09 06:58 AM
You are stating that the Rfm69_Read_Reg function causes the error and you didn't provide its source code.
Also, are you sure you must write then read, SPI is full duplex, you can write and read simultaneously.2015-10-09 07:28 AM
Hello,
Thank you for your reply. No the functionRfm69_Write_Reg() gives a problem. Only when I use theRfm69_Read_Reg() after theRfm69_Write_Reg() function the problem is gone. this is the implementation of theRfm69_Read_Reg():uint8_t Rfm69_Read_Reg(uint8_t address)
{
reg[0] = 0;
reg[1] = address & 0x7F;
HAL_SPI_TransmitReceive(&hspi1, (uint8_t *)reg, &data, 1, 1000);
return
data;
}
I'm aware of the fact that SPI is full duplex. But at the moment I was busy with the low level functions for reading and writing registers. So this is more some kind of test for the functions.
My sincerly,