You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
937 B

2 years ago
2 years ago
2 years ago
2 years ago
  1. #include <stdbool.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "main.h"
  6. #include "usart.h"
  7. #include "spi.h"
  8. #define READ_CMD 0xC0
  9. #define SPI_TIMEOUT_VALUE 1000
  10. #define SPI_CS_Enable() HAL_GPIO_WritePin(SPI_SEL_GPIO_Port, SPI_SEL_Pin, GPIO_PIN_RESET)
  11. #define SPI_CS_Disable() HAL_GPIO_WritePin(SPI_SEL_GPIO_Port, SPI_SEL_Pin, GPIO_PIN_SET)
  12. bool BSP_Read(uint8_t *pData, uint8_t register_address, uint32_t Size)
  13. {
  14. uint8_t cmd;
  15. cmd = 0XCA;
  16. // if (register_address <= 0x3F)
  17. // {
  18. // cmd += register_address;
  19. // }
  20. SPI_CS_Enable();
  21. HAL_SPI_Transmit(&hspi1, &cmd, 1, SPI_TIMEOUT_VALUE);
  22. // if (HAL_SPI_Receive(&hspi1, pData, Size, SPI_TIMEOUT_VALUE) != HAL_OK)
  23. // {
  24. // return false;
  25. // }
  26. SPI_CS_Disable();
  27. return true;
  28. }
  29. void user_main()
  30. {
  31. uint8_t temp;
  32. while (1)
  33. {
  34. BSP_Read(&temp, 0X3F, 1);
  35. // HAL_UART_Transmit(&huart1, &temp, 1, 100);
  36. // HAL_Delay(100);
  37. }
  38. }