2013-11-04

Eeprom function v0.0


// ***********************************************************************
// eeprom050.h 2013nov04hkt1440
// ***********************************************************************

#include "spi050.h"

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

#define DISABLE_WRITE_LATCH   0x04
#define ENABLE_WRITE_LATCH    0x06

#define WRITE_DATA_REGISTER   0x02
#define READ_DATA_REGISTER    0x03

#define DONT_CARE_DATA 0x00

// *** 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

void Mcp25Lc256v01(uint8_t spiChannelNumber)
{
    // *** Print project title ***********************************************
    printf("\n\n*** EEPROM MCP 25LC256 Test v01 - 2013nov04hkt1441 ***\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_DATA;;
    TxBuf[ADDRESS_UPPER_INDEX] = DONT_CARE_DATA;
    TxBuf[ADDRESS_LOWER_INDEX] = DONT_CARE_DATA;;
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 testXferConfig(SSP_DATA_SETUP_Type xferConfig, uint8_t spiChannelNumber)
{
uint8_t TxBuf[BUFFER_SIZE];
uint8_t RxBuf[BUFFER_SIZE];

    TxBuf[INSTRUCTION_INDEX]   = DONT_CARE_DATA;;
    TxBuf[ADDRESS_UPPER_INDEX] = DONT_CARE_DATA;
    TxBuf[ADDRESS_LOWER_INDEX] = DONT_CARE_DATA;;
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;

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

    SpiWriteRead050(xferConfig, spiChannelNumber);
}

.END

No comments:

Post a Comment