2019-12-11 07:12 AM
I am trying to receive 16bit data(at once) through SPI and transmit 8 bit data through USART.
clock frequency 16MHz.
All initialization done using STM32CubeMX. and build was successful .
but after writing following codes , control enters in Hard Fault at first byte receive.
variables declared:
uint16_t buffer_t[2];
uint8_t buffer_r[8];
uint8_t data_tx8[16];
codes written in while loop:
HAL_SPI_Receive(&hspi2,buffer_t,8,10000);
uint16_t j=buffer_t[1];
uint16_t k=buffer_t[0];
I am not able to understand why hard fault occurs here. (Same code runs properly if the code is configured only for SPI receive). I am using STM32L072 discovery kit.
thanks in advance.
2019-12-11 08:19 AM
Did you copy/paste your actual code above, or did you type it from memory? Because you are telling HAL_SPI_Receive() to receive 8 "things" of data, where a "thing" is either 8-bits or 16-bits depending on how you configured the SPI port, and the buffer you are passing is only 2 words long. Perhaps you meant "buffer_r" instead of "buffer_t".
Search these forms for "hard fault" and you should find LOTS of posts about tracking down the cause. Specifically, avagadro/clive @Community member has posted code samples to read/display the fault registers.
2019-12-11 08:34 AM
Yes , I should have given 2 in place of 8 things. this might be the reason for hard fault. Tomorrow I will run it and confirm.
Thanks for so quick response.
2019-12-11 09:52 AM
Get a proper Hard Fault Handler running.
The L0 (CM0) is going to be particularly sensitive to unaligned reads/writes. So look for code in the SPI driver, or wherever, that is casting a pointer to (uint16_t *) or (uint32_t *). This have a high probability in faulting.
2019-12-11 11:27 PM
yes it is working perfectly fine . thanks for help Bob S.