主题中讨论的其他器件:C2000WARE、 SysConfig、
大家好!
我将使用 spi_ex6_eeprom.c 示例与外部 FRAM (MB85RS2MTY)进行通信。
我编辑了该示例、以便将10个值写入 FRAM、并尝试回读:
// Included Files
#include "driverlib.h"
//#include "device.h"
#include "board.h"
// Defines
#define FRAM_ADDR 0x4F
#define NUM_BYTES 8
// SPI FRAM status
//#define MSG_STATUS_READY_M 0x0001 // FRAM is ready (not busy)
#define MSG_STATUS_WRITE_READY_M 0x0002 // FRAM
#define MSG_STATUS_BUSY 0xFFFF // FRAM is busy (internal write)
// Opcodes for the FRAM (8-bit)
#define RDSR 0x05
#define READ 0x03
#define WRITE 0x02
#define WREN 0x06
#define WRDI 0x04
#define WRSR 0x01
#define CS_LOW GPIO_writePin(CS_FRAM, 0)
#define CS_HIGH GPIO_writePin(CS_FRAM, 1)
// Function Prototypes
uint16_t readStatusRegister(uint16_t statusRegister);
void writeData(uint16_t address, uint16_t * data, uint16_t length, uint16_t txdly);
void readData(uint16_t address, uint16_t * data, uint16_t length, uint16_t txdly);
void enableWrite(void);
#define DUMMY_DATA 0
#define NO_DELAY 0
uint16_t SPI_readByte_FRAM(uint32_t base, uint16_t address);
uint16_t SPI_read16bits_FRAM(uint32_t base, SPI_endianess endianness, uint16_t address);
uint32_t SPI_read24bits_FRAM(uint32_t base, SPI_endianess endianness, uint16_t address);
uint32_t SPI_read32bits_FRAM(uint32_t base, SPI_endianess endianness, uint16_t address);
void done(void);
uint32_t base = SPIC_BASE;
#define BUFFER_SIZE 10
// Main
void main(void)
{
//uint16_t i;
//uint16_t pass = 0;
//uint16_t fail = 0;
// Initialize device clock and peripherals
Device_init();
// Disable pin locks and enable internal pullups.
Device_initGPIO();
// Board initialization
Board_init();
uint16_t TXbuff[BUFFER_SIZE] = {1,1,1,1,1,1,1,1,1,1}; //sample data to send to flash
//uint16_t TXbuff[BUFFER_SIZE] = {2,2,2,2,2,2,2,2,2,2}; //sample data to send to flash
uint16_t RXbuff[BUFFER_SIZE];
CS_HIGH;
// Enable write on the FRAM
enableWrite();
// Wait until the FRAM is ready to write data
//while((readStatusRegister(RDSR) & MSG_STATUS_WRITE_READY_M) == MSG_STATUS_WRITE_READY_M)
while((readStatusRegister(RDSR) & MSG_STATUS_WRITE_READY_M) == 0)
{
}
writeData(FRAM_ADDR, &TXbuff[0], BUFFER_SIZE, NO_DELAY); //Operazione di scrittura
// Read from the FRAM
readData(FRAM_ADDR, &RXbuff[0], BUFFER_SIZE,NO_DELAY);
}
uint16_t SPI_readByte_FRAM(uint32_t base, uint16_t address)
{
uint16_t RXdata = 0;
CS_LOW;
// Send the READ opcode.
SPI_transmitByte(base, READ);
// Send FRAM address to write data
SPI_transmit16Bits(base, address);
// Receive data byte from FRAM by sending dummy byte
RXdata = SPI_receiveByte(base, DUMMY_DATA);
CS_HIGH;
return(RXdata);
}
uint16_t SPI_read16bits_FRAM(uint32_t base, SPI_endianess endianness, uint16_t address)
{
uint16_t RXdata = 0;
CS_LOW;
// Send the READ opcode.
SPI_transmitByte(base, READ);
// Send FRAM address to write data
SPI_transmit16Bits(base, address);
// Receive data 16-bit word from FRAM by sending two dummy bytes
RXdata = SPI_receive16Bits(base, endianness, DUMMY_DATA, NO_DELAY);
CS_HIGH;
return RXdata;
}
uint32_t SPI_read24bits_FRAM(uint32_t base, SPI_endianess endianness, uint16_t address)
{
uint32_t RXdata = 0;
CS_LOW;
// Send the READ opcode.
SPI_transmitByte(base, READ);
// Send FRAM address to write data
SPI_transmit16Bits(base, address);
// Receive data 24-bit word from FRAM by sending three dummy bytes
RXdata = SPI_receive24Bits(base, endianness, DUMMY_DATA, NO_DELAY);
CS_HIGH;
return RXdata;
}
uint32_t SPI_read32bits_FRAM(uint32_t base, SPI_endianess endianness, uint16_t address)
{
uint32_t RXdata = 0;
CS_LOW;
// Send the READ opcode.
SPI_transmitByte(base, READ);
// Send FRAM address to write data
SPI_transmit16Bits(base, address);
// Receive data 32-bit word from FRAM by sending four dummy bytes
RXdata = SPI_receive32Bits(base, endianness, DUMMY_DATA, NO_DELAY);
CS_HIGH;
return RXdata;
}
// Function to send RDSR opcode and return the status of the FRAM
uint16_t readStatusRegister(uint16_t statusRegister)
{
uint16_t temp;
//uint32_t base = SPIA_BASE;
uint32_t base = SPIC_BASE;
// Pull chip select low.
CS_LOW;
// Send RDSR opcode
SPI_transmitByte(base, statusRegister);
// Send dummy data to read status register.
temp = SPI_receiveByte(base, 0x0);
// Pull chip select high.
CS_HIGH;
// Read the status from the receive buffer
return(temp);
}
// Function to send the WREN opcode
void enableWrite(void)
{
//uint32_t base = SPIA_BASE;
uint32_t base = SPIC_BASE;
// Pull chip select low.
CS_LOW;
// Send the WREN opcode.
SPI_transmitByte(base, WREN);
// Pull chip select high.
CS_HIGH;
}
// Function to write data to the FRAM
// - address is the byte address of the FRAM
// - data is a pointer to an array of data being sent
// - length is the number of characters in the array to send
void writeData(uint16_t address, uint16_t *data, uint16_t length, uint16_t txdly)
{
//uint32_t base = SPIA_BASE;
uint32_t base = SPIC_BASE;
// Pull chip select low.
CS_LOW; //in modo da dare al Chip Select lo stato attivo
// Send the WRITE opcode.
SPI_transmitByte(base, WRITE);
// Send FRAM address to write data
//SPI_transmit16Bits(base, address);
SPI_transmit24Bits(base, address, NO_DELAY);
// Send data to be programmed
SPI_transmitNBytes(base, data, length, txdly);
// Pull chip select high.
CS_HIGH; //in modo da dare al Chip Select lo stato standby
}
// Function to read data from the FRAM
// - address is the byte address of the FRAM
// - data is a pointer to an array of data being received
// - length is the number of characters in the array to receive
void readData(uint16_t address, uint16_t *data, uint16_t length, uint16_t txdly)
{
//uint32_t base = SPIA_BASE;
uint32_t base = SPIC_BASE;
CS_LOW;
// Send the READ opcode.
SPI_transmitByte(base, READ);
// Send FRAM address to write data
//SPI_transmit16Bits(base, address);
SPI_transmit24Bits(base, address, NO_DELAY);
// Receive length number of bytes
SPI_receiveNBytes(base, data, length, txdly);
CS_HIGH;
}
// End of File
从读取缓冲区来看、似乎所有字都正确写入/读取、但如果我将值更改为写入、在重新编程后、我看不到正确的值(读取的值都是0)、就像以前一样。
情况1: 首次刷新(uint16_t TXbuffle[buffer_size]={2、2、2、2、2、2、2、2};):

情况2: 第二次 刷写、地址相同(uint16_t TXbuffer_size]={1、1、1、1、1、1、1、1、1、1};)

问题可能是什么?
谢谢。此致。
詹尼








