2013-11-05

EEPROM function testing notes



























void testMcp25Lc256(uint8_t spiChannelNumber)
{
uint8_t statusRegisterValue;

printf("*** MCP25LC256 Test - 2013nov05hkt1246 ***\n\n");

setupSpi051(spiChannelNumber);

EepromWriteLatch(ENABLE_WRITE_LATCH, spiChannelNumber);
statusRegisterValue = EepromReadStatusRegister(spiChannelNumber);
printf("\n Write Latch enabled Status Register value = %02x ", statusRegisterValue);

EepromWriteLatch(DISABLE_WRITE_LATCH, spiChannelNumber);
statusRegisterValue = EepromReadStatusRegister(spiChannelNumber);
printf("\n Write Latch disabled Status Register value = %02x \n", statusRegisterValue);

printf("\n Now testing byte write ...\n");

EepromByteWrite(spiChannelNumber, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_55);
}



*** MCP25LC256 Test - 2013nov05hkt1246 ***

 Write Latch enabled Status Register value = 02 
 Write Latch disabled Status Register value = 00 

 Now testing by



// ***********************************************************************
// eeprom050.h 2013nov05hkt1116
// ***********************************************************************

#include "spi050.h"

// *** EEPROM Commands ***
#define WRITE_STATUS_REGISTER 0x01
#define READ_STATUS_REGISTER  0x05

#define DISABLE_WRITE_LATCH   0x04 // Disable latch = can write
#define ENABLE_WRITE_LATCH    0x06 // Enable latch = can NOT write

#define WRITE_DATA_REGISTER   0x02
#define READ_DATA_REGISTER    0x03

#define WRITE_PROTECT         0x01
#define HOLD                  0x01

#define DONT_CARE_INSTRUCTION 0x00
#define DONT_CARE_ADDRESS     0x00
#define DONT_CARE_DATA        0x00
#define DONT_CARE             0x00

#define WRITE_PROTECT_NONE          0x00
#define WRITE_PROTECT_UPPER_QUARTER 0x04 // 6000h-7FFFh
#define WRITE_PROTECT_UPPER_HALF    0x08 // 4000h-7FFFh
#define WRITE_PROTECT_ALL           0x0c // 0000h-7FFFh

// *** EEPROM Addresses ***

#define START_ADDRESS         0x0000
#define START_ADDRESS_UPPER     0x00
#define START_ADDRESS_LWER      0x00

#define TEST_ADDRESS          0x0300
#define TEST_ADDRESS_UPPER      0x03
#define TEST_ADDRESS_LOWER      0x00

#define TEST_DATA_BYTE_55    0x55
#define TEST_DATA_BYTE_AA    0xaa

void Mcp25Lc256v01(uint8_t spiChannelNumber)
{
    // *** Print project title ***********************************************
    printf("\n\n*** EEPROM MCP 25LC256 Test v01 - 2013nov05hkt1117 ***\n\n");

// *** Setup SPI transfer channels and buffers ***************************
setupSpi051(spiChannelNumber);

    // *** Setup 25LC256 instruction/data buffer ***********************

    #define BUFFER_SIZE 5
    #define INSTRUCTION_INDEX 0
    #define ADDRESS_UPPER_INDEX 1
    #define ADDRESS_LOWER_INDEX 2
    #define DATA_UPPER_INDEX 3
    #define DATA_LOWER_INDEX 4

#define DONT_CARE_INDEX_0 0
    #define DONT_CARE_INDEX_1 1
    #define DONT_CARE_INDEX_2 2
    #define DONT_CARE_INDEX_3 3
    #define DONT_CARE_INDEX_4 4

uint8_t TxBuf[BUFFER_SIZE];
uint8_t RxBuf[BUFFER_SIZE];

    // Setup xferConfig
    SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = TxBuf;
    xferConfig.rx_data = RxBuf;
    xferConfig.length = BUFFER_SIZE;

    // *** Initialize transfer buffers ***************************************

    TxBuf[INSTRUCTION_INDEX]   = DONT_CARE_INSTRUCTION;
    TxBuf[ADDRESS_UPPER_INDEX] = DONT_CARE_ADDRESS;
    TxBuf[ADDRESS_LOWER_INDEX] = DONT_CARE_ADDRESS;
TxBuf[DONT_CARE_INDEX_3]   = DONT_CARE_DATA;
TxBuf[DONT_CARE_INDEX_3]   = DONT_CARE_DATA;

RxBuf[DONT_CARE_INDEX_0] = DONT_CARE_DATA;
RxBuf[DONT_CARE_INDEX_1] = DONT_CARE_DATA;
RxBuf[DONT_CARE_INDEX_2] = DONT_CARE_DATA;
RxBuf[DATA_UPPER_INDEX]  = DONT_CARE_DATA;
RxBuf[DATA_LOWER_INDEX]  = DONT_CARE_DATA;

    SpiWriteRead050(xferConfig, spiChannelNumber);
}

void EepromWriteLatch(uint8_t eepromCommand, uint8_t spiChannelNumber)
{
    SSP_DATA_SETUP_Type xferConfig;
uint8_t TxBuf[1];
uint8_t RxBuf[1];

    TxBuf[0] = eepromCommand;
RxBuf[0] = DONT_CARE;

xferConfig.tx_data = TxBuf;
xferConfig.rx_data = RxBuf;
xferConfig.length = 1;

SpiWriteRead050(xferConfig, spiChannelNumber);

/* For debug only
uint8_t i;
for (i = 0; 1 < 100000; i++)
{
SpiWriteRead050(xferConfig, spiChannelNumber);
delayMilliSecond(1);
}
*/

}

uint8_t EepromReadStatusRegister(uint8_t spiChannelNumber)
{
    SSP_DATA_SETUP_Type xferConfig;
uint8_t TxBuf[2];
uint8_t RxBuf[2];

uint8_t statusRegisterValue;

xferConfig.tx_data = TxBuf;
xferConfig.rx_data = RxBuf;
xferConfig.length = 2;

    TxBuf[0] = READ_STATUS_REGISTER;
TxBuf[1] = DONT_CARE;
    RxBuf[0] = DONT_CARE;
RxBuf[1] = DONT_CARE;

SpiWriteRead050(xferConfig, spiChannelNumber);

/* *** For debugging only ***
uint8_t i;
for (i = 0; 1 < 100000; i++)
{
SpiWriteRead050(xferConfig, spiChannelNumber);
delayMilliSecond(1);
}
*/

statusRegisterValue = RxBuf[1];
return statusRegisterValue;
}

uint8_t EepromByteWrite(uint8_t spiChannelNumber, uint8_t upperAddress, uint8_t lowerAddress, uint8_t dataByte)
{
    SSP_DATA_SETUP_Type xferConfig;
uint8_t TxBuf[4];
uint8_t RxBuf[4];

xferConfig.tx_data = TxBuf;
xferConfig.rx_data = RxBuf;
xferConfig.length = 4;

    TxBuf[0] = WRITE_DATA_REGISTER;
TxBuf[1] = upperAddress;
TxBuf[2] = lowerAddress;
TxBuf[3] = dataByte;

    RxBuf[0] = DONT_CARE;
RxBuf[1] = DONT_CARE;
RxBuf[2] = DONT_CARE;
RxBuf[3] = DONT_CARE;

SpiWriteRead050(xferConfig, spiChannelNumber);

// *** For debugging only ***
uint8_t i;
for (i = 0; 1 < 100000; i++)
{
SpiWriteRead050(xferConfig, spiChannelNumber);
delayMilliSecond(1);
}
}

// Sample call
// EepromByteWrite(SPI_CHANNEL_1, TEST_ADDRESS_UPPER, TEST_ADDRESS_LOWER, TEST_DATA_BYTE_55);

.END

No comments:

Post a Comment