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.
80 lines
2.0 KiB
80 lines
2.0 KiB
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "main.h"
|
|
#include "usart.h"
|
|
#include "spi.h"
|
|
|
|
#define READ_CMD 0x80
|
|
#define SPI_TIMEOUT_VALUE 1000
|
|
#define SPI_CS_Enable() HAL_GPIO_WritePin(SPI_SEL_GPIO_Port, SPI_SEL_Pin, GPIO_PIN_RESET)
|
|
#define SPI_CS_Disable() HAL_GPIO_WritePin(SPI_SEL_GPIO_Port, SPI_SEL_Pin, GPIO_PIN_SET)
|
|
|
|
bool BSP_Read(uint8_t *pData, uint8_t register_address, uint32_t Size)
|
|
{
|
|
uint8_t cmd;
|
|
cmd = READ_CMD;
|
|
if (register_address <= 0x3F)
|
|
{
|
|
cmd += register_address;
|
|
}
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
|
|
SPI_CS_Enable();
|
|
HAL_SPI_Transmit(&hspi1, &cmd, 1, SPI_TIMEOUT_VALUE);
|
|
// if (HAL_SPI_Receive(&hspi1, pData, Size, SPI_TIMEOUT_VALUE) != HAL_OK)
|
|
// {
|
|
// return false;
|
|
// }
|
|
SPI_CS_Disable();
|
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_7, GPIO_PIN_SET);
|
|
return true;
|
|
}
|
|
|
|
// static void norflash_send_address(uint32_t address)
|
|
// {
|
|
// if (g_norflash_type == W25Q256) /* ֻ��W25Q256֧��4�ֽڵ�ַģʽ */
|
|
// {
|
|
// spi1_read_write_byte((uint8_t)((address) >> 24)); /* ���� bit31 ~ bit24 ��ַ */
|
|
// }
|
|
// spi1_read_write_byte((uint8_t)((address) >> 16)); /* ���� bit23 ~ bit16 ��ַ */
|
|
// spi1_read_write_byte((uint8_t)((address) >> 8)); /* ���� bit15 ~ bit8 ��ַ */
|
|
// spi1_read_write_byte((uint8_t)address); /* ���� bit7 ~ bit0 ��ַ */
|
|
// }
|
|
|
|
uint8_t spi1_read_write_byte(uint8_t txdata)
|
|
{
|
|
uint8_t rxdata;
|
|
HAL_SPI_TransmitReceive(&hspi1, &txdata, &rxdata, 1, 1000);
|
|
return rxdata;
|
|
}
|
|
|
|
void norflash_read(uint8_t *pbuf, uint32_t addr, uint16_t datalen)
|
|
{
|
|
uint16_t i;
|
|
|
|
SPI_CS_Enable();
|
|
spi1_read_write_byte(0X86);
|
|
|
|
// for (i = 0; i < datalen; i++)
|
|
// {
|
|
// pbuf[i] = spi1_read_write_byte(0XFF);
|
|
// }
|
|
|
|
SPI_CS_Disable();
|
|
}
|
|
|
|
void user_main()
|
|
{
|
|
uint8_t temp;
|
|
SPI_CS_Disable();
|
|
|
|
while (1)
|
|
{
|
|
// BSP_Read(&temp, 0X06, 1);
|
|
norflash_read(&temp, 0x06, 1);
|
|
|
|
// HAL_UART_Transmit(&huart1, &temp, 1, 100);
|
|
HAL_Delay(100);
|
|
}
|
|
}
|