element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • 'Choose another store...'
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs Talk SPI to EEPROM with Hercules Launchpad - part 4: First Trial on the RM46
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 29 May 2015 7:20 PM Date Created
  • Views 1320 views
  • Likes 1 like
  • Comments 6 comments
  • hercules_launchpad
  • rm46
  • microchip
  • EEPROM
  • spi
  • texas_instruments
  • serial
  • protocol
Related
Recommended

Talk SPI to EEPROM with Hercules Launchpad - part 4: First Trial on the RM46

Jan Cumps
Jan Cumps
29 May 2015

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.

 

image

 

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.

 

image

 

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.

 

image

 

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

 

image

 

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 image 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:

image image

 

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

 

image

 

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...

 

image

 

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
  • Sign in to reply

Top Comments

  • martinvalencia
    martinvalencia over 8 years ago +1
    Jan Cumps really see that you are still working on this project; I dedicate the weekend to match me to work; Thanks for your hard work and hope you get great results, Greetings friend!
  • Jan Cumps
    Jan Cumps over 8 years ago +1
    martinvalencia has a working version, by bitbanging the CS function. Talk SPI to EEPROM with Hercules Launchpad Hero THere's a 'cs hold' option available on the MIBSPI setup for Hercules, that may be worth…
  • martinvalencia
    martinvalencia over 8 years ago in reply to Jan Cumps +1
    I was watching the MibSPI settings, while not quite understand the configuration of the data group, I will take me a while to finish translating and understanding the datasheet :-)
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to martinvalencia

    MibSPI is the multi-buffered variant. To see what data groups are doing, you can check one of the MibSPI tabs in HALCoGen. You can use it to talk to different slaves from the same peripheral. Or to set up different data lenght, ....

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • martinvalencia
    martinvalencia over 8 years ago in reply to Jan Cumps

    if I no use data group, the module MibSPI is the same as a common SPI, which is the difference between what add the data group to module SPI?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to martinvalencia

    The data groups are a neat feature. You can define multiple data setups, and witch between them.

    if you don't want tu use it, jsut configure the first group and select it.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • martinvalencia
    martinvalencia over 8 years ago in reply to Jan Cumps

    I was watching the MibSPI settings, while not quite understand the configuration of the data group, I will take me a while to finish translating and understanding the datasheet :-)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago

    martinvalencia has a working version, by bitbanging the CS function.

    Talk SPI to EEPROM with Hercules Launchpad  Hero

     

    THere's a 'cs hold' option available on the MIBSPI setup for Hercules, that may be worth looking at ( to see if MIBSPI works, and to see if the HOLD function is also available in standard SPI).

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube