STM32F1 SPI Simpleton Implementation Fail
Hi Ben,
First of all you should check that in your project settings at “project >> C/C++ Build >> Settings >> Tool Settings >> MCU GCC Compiler >> Warnings” the “All Warnings (-Wall)” option is checked. This will gives you warnings on potential errors you may have in your code.
Second, there is indeed several problems in your code:
- You do not need any parentheses in
(pData) =; you can write it simply aspData = - pData, as its name implies, should be a pointer to uint8_t data (bytes);
- You should declare it as
uint8_t *pData; - Then you cannot assign it a byte, you must assign it the address of a byte, by
pData = &TheDataItself; - Finally you can pass to HAL_SPI_Transmit either
pDataor&TheDataItself, both will request HAL to transmit 1 byte of data (value ofcnt), located in theTheDataItselfvariable
- You should declare it as
uint8_t TheDataItself = 0xFF; HAL_SPI_Transmit(&hspi2, &TheDataItself, sizeof(TheDataItself), 10); // 10 is the time out value.
Finally, I think you should read one of the numerous C programming courses you can find on the web: whatever it may look like, C is not a simple programming language, especially when going to pointers, and you need some guidance when starting to program in C.
Hope this helps clarifying things,
Bernard (Ac6)


