|
楼主 |
发表于 2023-9-14 00:19:21
|
显示全部楼层
您好 我现在用spi去读FRAM,但是总是读出来是0.我通过示波器看SCK MISO CS应该都是对的 但是就是MOSI一直有问题 能帮忙看一下为什么嘛?
这是我的控制代码:
/*
* spi_fram.c
*
* Created on: Sep 12, 2023
* Author: 11986
*/
#include "spi_fram.h"
uint8_t spi1_read_write_byte(uint8_t data)
{
uint8_t rec_data = 0;
HAL_SPI_TransmitReceive(&hspi1, &data, &rec_data, 1, 1000); //spi读写数据函数,参数2存放用来发送的数据,参数3存放用来接收的数据
return rec_data;
}
static void FRAM_send_address(uint32_t address) /*address: 0x00 ~ 0x7FFFF */
{
spi1_read_write_byte((uint8_t)((address)>>16)); /* send bit23 ~ bit16 */
spi1_read_write_byte((uint8_t)((address)>>8)); /* send bit15 ~ bit8 */
spi1_read_write_byte((uint8_t)address); /* send bit7 ~ bit0 */
}
uint16_t FramReadID(){
// uint8_t cmd = RDID;
// uint8_t idReg[8]={0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F};
// uint8_t i,errors;
// uint8_t idregFactory[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
// HAL_SPI_Transmit(&hspi1, &cmd, 1, 1000);
// HAL_SPI_Receive(&hspi1, idReg, 8, 1000);
// HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
// errors = 0;
// for (i=0;i<8;i++){
// if(idReg[i]!=idregFactory[i]) errors++;
// }
// return errors;
uint16_t deviceid;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
spi1_read_write_byte(RDID); /* 发送读取 ID 命令 */
deviceid = spi1_read_write_byte(0xFF) << 8; /* Read high 8 bit */
//deviceid |= spi1_read_write_byte(0xFF); /* Read low 8 bit */
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
return deviceid;
}
void FramInit(void)
{
spi1_read_write_byte(0xFF); /* Write 0xFF to DR */
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
}
|
|