My Peruvian mate martinvalencia and I purchased a set of 25LC256 SPI serial EEPROM chips.

Our plan was to get them working with the Texas Instruments Hercules LaunchPad MK II.

That was back in January. And then we stalled.

Martin has restarted the exercise and I'm going to play along.

 

This blog is our path from Zero to Hero.
This time I'm running my first trial on the LaunchPad. I get a reply but timing isn't ok yet.

Feel free to jump all over us while we're doing things the wrong way.

 

Photo 29-05-15 20 33 50.jpg

 

Warning: this setup isn't working yet. Don't copy the code from this blog into your project.

In the list of related posts at the bottom of this page, you'll find a post of martinvalencia that works.

 

 

 

Setting Up the Hercules Project

 

There's two main tools that we're using to set up a project for Hercules devices.

HALCoGen, the visual configuration tool that we use to enable and  set up peripherals.

Code Composer Studio, the IDE where we write, compile and debug firmware.

 

Priming the project in HALCoGen

 

The first step is to define our building blocks in HALCoGen.

The application lets us choose what peripherals we want to use, and how we want to configure them.

HALCoGen will then generate the driver API and initialization C code for us. We'll use that generated code later in our firmware.

 

When you create a project in HALCoGen, you select the right controller, and give the project a name.

 

 

Select the Code Composer Studio workspace directory as location, This will make your work easier later on.

Enable the SPI driver. You can see in part 2: Circuit and Test Bed why I'm selecting SPI3.

 

 

On the multiplexing page, I've activated the SPI3 pins.

 

 

I first selected the global MIBSPI3 checkbox, That activates all SPI3 related pins. Because I only need 4 of them, I've deactivated the ones I don't need.

(I've kept SOMI, SIMO, CLK and CS_0. Others, like CS_1, CS_2, ..., ENA I've deselected again because I'm not using them.

This is not strictly neccessary, but my personal style is to only make pins functional that I'm using, and leave others in their default assignment.)

 

I've configured the SPI peripheral, loosely based on the memory's datasheet:

 

(note that my baudrate is awfully off. I have to downscale the SPI clock too get within a reasonable range for the , but haven't done that yet:

 

I've only defined the pins that I am using:

 

 

Then I generated the source in HALCoGen.

 

Writing Firmware in CCS

 

When you create an empty project inj CCS, and you leave the working directory as default, your HALCoGen code is automaticaly part of your project.
Just don't forget to add the include folder in the project's include settings.

 

In the code, you need to do 2 steps:

Call the init code of the devices you activated in HALCoGen (for this project, that's SPI.

 

#include "spi.h"
    spiInit();



 

Use the API functions that HALCoGen generated to do the business.

 

#define CS_0 0xFEU

uint16 eeprom_write_enable[1] = {6};
uint16 eeprom_write_disable[1] = {4};


uint16 eeprom_bytewrite[4] = {0x02, 0x00, 0x00, 0xAA}; // write 10101010 to address 0x0000
uint16 eeprom_byteread[4] = {0x03, 0x00, 0x00, 0x00}; // read from address 0x0000 (last byte is dummy, placeholder for result




uint16 Result25LC256[5] = { 0x00, 0x00, 0x00, 0x00, 0x00 };


    spiDAT1_t dataconfig1_t;


    dataconfig1_t.CS_HOLD = TRUE;
    dataconfig1_t.WDEL = TRUE;
    dataconfig1_t.DFSEL = SPI_FMT_0;
    dataconfig1_t.CSNR = CS_0;

    spiTransmitAndReceiveData(spiREG3, &dataconfig1_t, 4, eeprom_byteread,Result25LC256);



 

 

 

That doesn't give me a working program yet. My data is sent to the memory, and I get a reply back.

But the reply arrives too late. All my SPI clock pulses have long been used before the EEPROM sends its reply.

A second issue I have to resolve is that my CS doesn't stay low during communication...

 

 

The next post will be an attempt to resolve these issues...

 

 

Related posts
part 1: from Zero to Hero
part 2: Circuit and Test Bed
part 3: Testing SPI Protocol with Bus Pirate
part 4: First Trial on the RM46
martinvalencia's Talk SPI to EEPROM with Hercules Launchpad